Skip to content

various speed optimizations#12

Merged
freyfogle merged 1 commit intomasterfrom
speed-optimizations
Feb 11, 2026
Merged

various speed optimizations#12
freyfogle merged 1 commit intomasterfrom
speed-optimizations

Conversation

@freyfogle
Copy link
Member

@freyfogle freyfogle commented Feb 11, 2026

  1. Cached compiled Mustache templates — $THC->compile() results are now memoized in $self->{compiled_template_cache} keyed by template text, avoiding recompilation on every call.

  2. Removed redundant clone — The second clone() in _render_template was removed since Text::Hogan::Template->render() doesn't mutate its context.

  3. Pre-compiled replacement regexes — _precompile_rules() runs at config load time, compiling all replace and postformat_replace regex patterns into qr// objects. The hot-loop try/catch blocks in _apply_replacements and _postformat are eliminated. Legacy raw-array format is still supported for backward compatibility with direct callers.

  4. Built reverse lookup hashes for state/county codes — _build_code_lookups() creates {state_codes_reverse} and {county_codes_reverse} hashes at config time, turning O(n) linear scans in _add_code into O(1) hash lookups.

  5. Pre-compiled abbreviation regexes — _precompile_abbreviations() compiles qr/(^|\s)\Q$long\E\b/ patterns once at load time, stored in {compiled_abbreviations}. _abbreviate() uses these directly.

…ow memoized in $self->{compiled_template_cache} keyed by template text, avoiding recompilation on every call.

2. Removed redundant clone — The second clone() in _render_template was removed since  Text::Hogan::Template->render() doesn't mutate its context.

3. Pre-compiled replacement regexes — _precompile_rules() runs at config load time, compiling all replace and postformat_replace regex patterns into qr// objects. The hot-loop try/catch blocks in _apply_replacements and _postformat are eliminated. Legacy raw-array format is still supported for backward compatibility with direct callers.

4. Built reverse lookup hashes for state/county codes — _build_code_lookups() creates {state_codes_reverse} and {county_codes_reverse} hashes at config time, turning O(n) linear scans in  _add_code into O(1) hash lookups.

5. Pre-compiled abbreviation regexes — _precompile_abbreviations() compiles qr/(^|\s)\Q$long\E\b/ patterns once at load time, stored in {compiled_abbreviations}. _abbreviate() uses these directly.
@freyfogle freyfogle merged commit 86de5ce into master Feb 11, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant