From 21469c553d5280446396d2ef7ee80701aac1b065 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 16 Aug 2022 09:58:36 +0200 Subject: [PATCH] rc ledger: don't use region highlighter for simple keywords MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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' --- rc/filetype/ledger.kak | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rc/filetype/ledger.kak b/rc/filetype/ledger.kak index 0bd52ea0..31417b78 100644 --- a/rc/filetype/ledger.kak +++ b/rc/filetype/ledger.kak @@ -64,12 +64,14 @@ add-highlighter shared/ledger/other region '^(P|=|~)' '$' fill meta # The following highlighters implement # 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 evaluate-commands %sh{ # TODO: Is `expr` also a command directive? The documentation confuses me. for cmd in 'apply account' 'apply fixed' 'assert' 'bucket' 'check' 'end' \ '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 }