Skip to content

Syntax highlighting is SLOW #15

@pyrocat101

Description

@pyrocat101

This tool is pretty slow when I tried piping a large diff to it, taking nearly 4 seconds. So I profiled it with perf and found that a lot of time is spent in the WASM library (https://github.com/NeekSandhu/onigasm) indirectly used by https://github.com/shikijs/shiki/.

Screen Shot 2021-05-02 at 21 25 17

If I comment out the usage of highlightSyntaxInLine, then it takes less than 500ms to display the previous diff. This is the perf report:

Screen Shot 2021-05-02 at 21 18 41

Have you considered:

  1. Provide CLI flag to turn off the syntax highlighter (right now it seems to be tied to the theme setting).
  2. Use a more performant syntax highlighter implementation. Anecdotally, WASM is much slower than the native, and the call between JS and WASM is also extremely expensive. This worsens when you only call the highlighter one line at a time.

For comparison, https://github.com/dandavison/delta uses https://github.com/trishume/syntect and is very fast.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions