⚡ Bolt: Extract dynamic regexp compilations to package-level globals#34
⚡ Bolt: Extract dynamic regexp compilations to package-level globals#34lleontor705 wants to merge 1 commit intodevelopfrom
Conversation
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.
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Superseded by #35 (latest Bolt regex optimization, already merged). |
💡 What: Moved dynamically compiled regular expressions (
regexp.MustCompile) inside frequently executed functions (such ascleanMarkdown,extractLearnings,normalizeTopicSegment, andsanitizeMigrationName) to package-level global variables.🎯 Why:
regexp.MustCompileallocates 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 rungo test -bench . -benchmem ./...ininternal/mcpto verify the overhead reduction.PR created automatically by Jules for task 4734287691351522287 started by @lleontor705