zsh-users/zsh-syntax-highlighting

Is optimization via integer-indexed hash possible?

Open

#366 建立於 2016年9月16日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)Shell (22,617 star) (1,371 fork)batch import
good first issueperformance

描述

As Daniel pointed out, appends to region_highlight might be expensive. This reminded me coding https://github.com/psprint/zsh-morpho, where I used associative array indexed with integers instead of regular array. The image and needed array size is $LINES * $COLUMNS, say 6903 on my current terminal, which is not very large size, and when I compared hash vs array runs, it basically meant that with arrays one could go get a coffee multiple times. Maybe I'll provide numbers, but for hash it was ~7 seconds.

So, if highlighters would keep integer index=1, store at it into hash and increment, and then at the end move entries from hash into region_highlight at one go, this should improve performance.

PS. I checked region_highlight size produced by main-highlighter.zsh when parsing itself (754 lines), and its 686 entries, so not close to 6903, however we still might get 100 ms or more, which counts for zsyh-enabled vared and say 500 line functions edited with it (I already enable zsyh for vared).

貢獻者指南