zsh-users/zsh-syntax-highlighting

Is optimization via integer-indexed hash possible?

Open

#366 创建于 2016年9月16日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)Shell (1,371 fork)batch import
good first issueperformance

仓库指标

Star
 (22,617 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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).

贡献者指南