google / mdbook-i18n-helpers

Translation support for mdbook. The plugins here give you a structured way to maintain a translated book.
Apache License 2.0
126 stars 25 forks source link

Cache `SyntaxSet` between `parse_codeblock` calls #147

Closed mgeisler closed 7 months ago

mgeisler commented 7 months ago

Before we would load and deserialize the syntect syntax trees (Sublime Text syntax definitions) on every call. We now cache this read-only data.

Before, mdbook build took 1.44 s, now it takes 0.56 s instead. I started looking in to optimizing this because I'm considering making mdbook-xgettext an (optional) plugin in book.toml for Comprehensive Rust. This will imply that we run the plugin on every mdbook build — at least for people like me who have the plugin installed.

codecov-commenter commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (ec5968c) 90.64% compared to head (62c36d2) 90.64%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #147 +/- ## ======================================= Coverage 90.64% 90.64% ======================================= Files 11 11 Lines 2372 2373 +1 Branches 2372 2373 +1 ======================================= + Hits 2150 2151 +1 Misses 159 159 Partials 63 63 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

kdarkhan commented 7 months ago

Just a thought - maybe we should add several bench targets so that we can find how performance of the code changes. Does not have to be exposed during PR build but something that is easy to trigger locally.

mgeisler commented 7 months ago

Just a thought - maybe we should add several bench targets so that we can find how performance of the code changes. Does not have to be exposed during PR build but something that is easy to trigger locally.

That would indeed be a useful tool to have!

For this, I used https://github.com/sharkdp/hyperfine like this:

% MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages-10.pot", "granularity": 10}}' hyperfine 'mdbook build -d po'

to test only mdbook-xgettext. But if we could put this into a criterion benchmark as well, then that would be nice.