shikijs / shiki

A beautiful yet powerful syntax highlighter
http://shiki.style/
MIT License
9.19k stars 330 forks source link

perf: improve performance for the `includeExplanation` option #701

Closed thetarnav closed 2 weeks ago

thetarnav commented 2 weeks ago

This improves the performance for using codeToTokens with includeExplanation option enabled.

I'm working with a file that is 3k lines long, and getting the tokens with explanations was taking way too much time, around 7 to 9 seconds.

Turns out that the explainThemeScope function was redoing a decent amount of work for each token, for each scope, and for each setting, without depending on any of those. So it would be calculated once and reused.

Now I get tokens for that file in ~1.5s

Probably could be improved more, but I didn't want to change any logic.

netlify[bot] commented 2 weeks ago

Deploy Preview for shiki-next ready!

Name Link
Latest commit 19c59a98611278b1cfe3f3210c038d751b510fe3
Latest deploy log https://app.netlify.com/sites/shiki-next/deploys/666dd6731ef92d0008b490e2
Deploy Preview https://deploy-preview-701--shiki-next.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] commented 2 weeks ago

Deploy Preview for shiki-matsu ready!

Name Link
Latest commit 19c59a98611278b1cfe3f3210c038d751b510fe3
Latest deploy log https://app.netlify.com/sites/shiki-matsu/deploys/666dd673148c0e0008b5f17f
Deploy Preview https://deploy-preview-701--shiki-matsu.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.