Skip to content

⚡ Bolt: pre-compile regexes in tools_memory.go#33

Open
lleontor705 wants to merge 1 commit intodevelopfrom
bolt-optimize-regexp-3976586067971291876
Open

⚡ Bolt: pre-compile regexes in tools_memory.go#33
lleontor705 wants to merge 1 commit intodevelopfrom
bolt-optimize-regexp-3976586067971291876

Conversation

@lleontor705
Copy link
Copy Markdown
Owner

💡 What: Refactored multiple inline regexp.MustCompile calls in internal/mcp/tools_memory.go (specifically in functions normalizeTopicSegment, extractLearnings, and cleanMarkdown) to be package-level global variables. Added an entry to the .jules/bolt.md journal to document this optimization.

🎯 Why: regexp.MustCompile allocates memory and parses the regular expression state machine every single time it is called. When used inside functions that are called frequently or in loops, this introduces unnecessary per-call overhead and heap allocations. Pre-compiling them at the package level completely eliminates this runtime cost.

📊 Impact: Reduces CPU overhead and heap memory allocations during memory tool operations (specifically topic key normalization and learning extraction) by reusing thread-safe, pre-compiled state machines.

🔬 Measurement: Verified correctness via unit tests (go test ./...) which continue to pass identically. Performance improvement could be measured via go test -bench on the relevant normalizeTopicSegment and extractLearnings functions before and after the change, showing fewer allocs/op and reduced ns/op.


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

@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.

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