perf(i18n): replace regex in t() with replaceAll#2176
Conversation
|
Heads up — #2162 just merged and already includes a The |
Replace per-key `new RegExp(\`\\{${k}\\}\`, "g")` with native
`replaceAll(\`{${k}}\`, String(v))` — avoids regex construction overhead
on every translation lookup. ReadConfig cache already merged in esengine#2162.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
8886195 to
7262a4e
Compare
esengine
left a comment
There was a problem hiding this comment.
Re-reviewed — trimmed exactly as discussed: now just src/i18n/index.ts, dropping the redundant (and TOCTOU-prone) readConfig cache that #2162 already covers, keeping only the t() win — result.replaceAll(\{${k}}`, String(v))instead ofnew RegExp(`\{${k}\}`, "g")` per key. Equivalent (literal global replace) and avoids constructing a RegExp per placeholder per call. CI green. Merging.
Summary
Replace per-key
new RegExp(\\{${k}\}`, "g")with nativereplaceAll(`{${k}}`, String(v))in thet()` translation function — avoids regex construction overhead on every translation lookup.The
readConfigmtime cache that was originally in this PR has been dropped — it's already in #2162 (which uses an fd-based approach to avoid a TOCTOU race flagged by CodeQL).Files changed (1)
src/i18n/index.tsresult.replace(new RegExp(...))→result.replaceAll(...)Test plan
t("key", { name: "value" })still substitutes{name}correctly🤖 Generated with Claude Code