Experiment [iteration 2]: Using syntect as a higlighting backend rather than highlight.js #1624
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'd rather not copy out the entire description of the previous iteration, so I'll just link it here: #1494
This iteration has much better performance than the previous iteration:
Syntect v2Syntect v1HLJS(measured on my machine using
hyperfine, building the Rust Book; "Syntect v1" = #1494, "Syntect v2" = this fork/PR, "HLJS" = upstream mdBook)There's still some performance improvements to be made, and a lot of it seems to be from
hbs_renderer::add_playground_pre. This function searches through the entirety of the HTML content of a page and searches for Rust code blocks which need a "preamble" (containing anfn main() {}that wraps the original code). However, this is done after code is syntax highlighted, and the resulting code is quite verbose thanks to how syntect highlights code (this is more due to how tmLanguage/sublime-syntax definitions work, than to the implementation of syntect, however). This means that searching through a bunch of code blocks is quite slow in practice.As I noted here, this step could be moved to before syntax highlighting, which would not only reduce the number of edge cases and weirdness due to odd syntax highlighting, but would also probably be faster. I'll probably do this at some point, and see if it actually helps with performance. Based on my profiling, though, it seems that this function is the major performance issue.
TODO
As this is such a major change to the Handlebars backend, here is a list of things that should be done before this is minimally useful in production: