Skip to content

⚡ Bolt: Extract dynamic regexp compilations to package-level globals#34

Closed
lleontor705 wants to merge 1 commit intodevelopfrom
bolt-optimize-regexp-compilation-4734287691351522287
Closed

⚡ Bolt: Extract dynamic regexp compilations to package-level globals#34
lleontor705 wants to merge 1 commit intodevelopfrom
bolt-optimize-regexp-compilation-4734287691351522287

Conversation

@lleontor705
Copy link
Copy Markdown
Owner

💡 What: Moved dynamically compiled regular expressions (regexp.MustCompile) inside frequently executed functions (such as cleanMarkdown, extractLearnings, normalizeTopicSegment, and sanitizeMigrationName) to package-level global variables.

🎯 Why: regexp.MustCompile allocates memory and parses the regex state machine each time it is called. When called inside a hot loop or a frequently invoked utility function, this causes unnecessary heap allocations and execution time penalties. Initializing these static expressions as thread-safe package-level globals completely eliminates the per-call overhead.

📊 Impact: Significantly reduces CPU cycles and heap allocations during markdown parsing, text sanitation, and topic key generation, especially noticeable when processing large observations or iterating over multiple document sections.

🔬 Measurement: Go benchmarks profiling the string parsing paths (cleanMarkdown, extractLearnings) will show lower memory allocations (allocs/op) and faster execution times. You can run go test -bench . -benchmem ./... in internal/mcp to verify the overhead reduction.


PR created automatically by Jules for task 4734287691351522287 started by @lleontor705

This commit moves multiple `regexp.MustCompile` statements inside heavily used string-processing functions (e.g., markdown parsing, text sanitation) to package-level global variables. This avoids recompiling the state machine on every function call, reducing CPU overhead and heap allocations.
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@lleontor705
Copy link
Copy Markdown
Owner Author

Superseded by #35 (latest Bolt regex optimization, already merged).

@google-labs-jules
Copy link
Copy Markdown

Superseded by #35 (latest Bolt regex optimization, already merged).

Understood. Acknowledging that this work is now obsolete as it has been superseded by #35 and stopping work on this task.

@lleontor705 lleontor705 deleted the bolt-optimize-regexp-compilation-4734287691351522287 branch April 11, 2026 00:25
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