Skip to content

[Repo Assist] perf: compile regex instances to module-level singletons#1162

Draft
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/perf-compile-regex-2026-04-10-f88f43f8587c44e1
Draft

[Repo Assist] perf: compile regex instances to module-level singletons#1162
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/perf-compile-regex-2026-04-10-f88f43f8587c44e1

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist.

Summary

Compile Regex instances to module-level singletons in five locations that were creating a new, uncompiled Regex on every call.

Problem

Location Called when
PageContentList.mkPageContentMenu Once per rendered HTML page
Formatting.fs (search-index strip) Once per HTML page
HtmlFormatting.formatAnchor Once per heading per page
Menu.snakeCase Once per navigation menu item
LlmsTxt.collapseBlankLines / normaliseTitle Twice per page for llms.txt

Each call compiled the regex pattern from scratch, incurring unnecessary JIT overhead proportional to the number of pages/headings/menu items.

Fix

Promote each Regex to a private module-level let binding with RegexOptions.Compiled. The pattern is compiled once at module load and reused for every subsequent call.

Test Status

Build: 0 warnings, 0 errors
Tests: 281/281 Markdown tests pass


Generated by 🌈 Repo Assist, see workflow run.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@e1ecf341a90b7bc2021e77c58685d7e269e20b99

Five locations were creating a new uncompiled Regex on every call:

- PageContentList.mkPageContentMenu: new Regex per page rendered
- Formatting.fs (search index): Regex.Replace (static, uncompiled) per HTML page
- HtmlFormatting.formatAnchor: Regex.Matches per heading processed
- Menu.snakeCase: Regex.Replace (static, uncompiled) per menu item
- LlmsTxt (collapseBlankLines, normaliseTitle): two Regex.Replace per page entry

Each is now a module-level let binding with RegexOptions.Compiled, so the
pattern is compiled once at startup and reused for the lifetime of the
process.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants