Hacker News new | past | comments | ask | show | jobs | submit login

The problem with Shiki is that it uses TextMate grammars which in turn require the Oniguruma regex engine. Shiki compiles that to WASM I believe, but it makes Shiki larger and slower than a system that uses plain JavaScript regexes or a real parser.

I'd only use it if it's absolutely necessary that your syntax highlighting exactly matches VS Code. (It's also a shame that VS Code requires Oniguruma)




> I'd only use it if it's absolutely necessary that your syntax highlighting exactly matches VS Code. (It's also a shame that VS Code requires Oniguruma)

This more important than you state. I have many JS syntax highlighters and most of them are garbage. Like, they don't even recognize some obvious keywords like `const`, `async` and `await` for Javascript. I'd rather chose something with better inbuilt grammar. I am not sure what the slowdown is like, but I don't imagine it'd be much. And with SSR, you can even offload it to a server and cache the generated HTML.


Coincidentally, I recently looked into the slow startup time for shiki and it was mostly from parsing JSONC, not WASM: https://github.com/shikijs/shiki/issues/439.


Hmm, I don't see why it's parsing it at all. It could just be inside the rust source code. And it might be faster to run, not just faster to load.


Not all WASM files are in the same ballpark. This one is 500K while esbuild is almost 10MB.

https://cdn.jsdelivr.net/npm/shiki@0.14.1/dist/

https://cdn.jsdelivr.net/npm/esbuild-wasm/

That's no knock on esbuild. esbuild benefits from having been built with golang and wasn't designed to be run in the browser. (tinygo can run go in much smaller but you give up some of golang's power)

WASM is fast becoming a standard thing.


500k to mostly duplicate an existing platform feature? No thanks.


What feature are you referring to?


Regular expressions it seems. I disagree that it's a duplicate or a waste. It's a different regex engine with different features.


Yes, I have also noticed that Shiki is slower. We use it in our blogging platform for code block highlighting and posts with code blocks are noticeably slower to save than posts without them.

Are there any alternatives that supports VS Code syntax but faster?


In the examples it doesn't seem to match VS Code at all. It's way less colourful and missing useful features like different colours for nested brackets.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: