i18next speeds up translation up to 5x with two includes() checks
A developer reported that two simple includes() checks made the i18next translation library up to five times faster on long text. The library's interpolation and nesting regexes ran on every translated string, even though most strings contain neither required prefix, so a fast prefix check lets them skip the costly scan. Benchmarks showed an 81% reduction in time for a 10 KB text, with output unchanged across a large randomized test. The same approach of a cheap pre-check was also applied to the regexp2 engine for Go, where an ASCII fast path cut pattern compilation time by about 70%. A similar regex rewrite in the colord CSS color parser was also described as avoiding redundant digit scanning.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in