rc ledger: don't use region highlighter for simple keywords

As reported in
https://github.com/mawww/kakoune/issues/4685#issuecomment-1200530001
ledger.kak defines a region end that matches every character of
the buffer. This causes performance issues for large buffers.
Since the affected regions are only ever filled with a single color,
just use a regex highlighter instead of a region highlighter.
This improves performance when loading the file for the first time.

Speedup on [example.journal.txt](https://github.com/mawww/kakoune/issues/4685#issuecomment-1193243588)

	$ HOME=$PWD hyperfine -w 1 'git checkout HEAD'{~,}' -- :/rc/filetype/ledger.kak && ./kak.opt example.journal.txt -e "modeline-parse; hook global NormalIdle .* quit" -ui dummy'
	Benchmark 1: git checkout HEAD~ -- :/rc/filetype/ledger.kak && ./kak.opt example.journal.txt -e "modeline-parse; hook global NormalIdle .* quit" -ui dummy
	  Time (mean ± σ):     362.1 ms ±   5.1 ms    [User: 336.6 ms, System: 30.2 ms]
	  Range (min … max):   352.6 ms … 369.1 ms    10 runs
	 
	Benchmark 2: git checkout HEAD -- :/rc/filetype/ledger.kak && ./kak.opt example.journal.txt -e "modeline-parse; hook global NormalIdle .* quit" -ui dummy
	  Time (mean ± σ):     271.2 ms ±  16.7 ms    [User: 252.8 ms, System: 24.0 ms]
	  Range (min … max):   253.9 ms … 305.0 ms    10 runs
	 
	Summary
	  'git checkout HEAD -- :/rc/filetype/ledger.kak && ./kak.opt example.journal.txt -e "modeline-parse; hook global NormalIdle .* quit" -ui dummy' ran
	    1.33 ± 0.08 times faster than 'git checkout HEAD~ -- :/rc/filetype/ledger.kak && ./kak.opt example.journal.txt -e "modeline-parse; hook global NormalIdle .* quit" -ui dummy'
This commit is contained in:
Johannes Altmanninger 2022-08-16 09:58:36 +02:00
parent 021da117cf
commit 21469c553d

View File

@ -64,12 +64,14 @@ add-highlighter shared/ledger/other region '^(P|=|~)' '$' fill meta
# The following highlighters implement # The following highlighters implement
# https://www.ledger-cli.org/3.0/doc/ledger3.html#Command-Directives # https://www.ledger-cli.org/3.0/doc/ledger3.html#Command-Directives
add-highlighter shared/ledger/default default-region group
# Add highlighters for simple one-line command directives # Add highlighters for simple one-line command directives
evaluate-commands %sh{ evaluate-commands %sh{
# TODO: Is `expr` also a command directive? The documentation confuses me. # TODO: Is `expr` also a command directive? The documentation confuses me.
for cmd in 'apply account' 'apply fixed' 'assert' 'bucket' 'check' 'end' \ for cmd in 'apply account' 'apply fixed' 'assert' 'bucket' 'check' 'end' \
'include' 'apply tag' 'test' 'year'; do 'include' 'apply tag' 'test' 'year'; do
echo "add-highlighter shared/ledger/ region '^${cmd}' '.' fill function" echo "add-highlighter shared/ledger/default/ regex '^${cmd}\b' 0:function"
done done
} }