⚡ Bolt: pre-compile regexes in tools_memory.go#33
⚡ Bolt: pre-compile regexes in tools_memory.go#33lleontor705 wants to merge 1 commit intodevelopfrom
Conversation
|
👋 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. |
💡 What: Refactored multiple inline
regexp.MustCompilecalls ininternal/mcp/tools_memory.go(specifically in functionsnormalizeTopicSegment,extractLearnings, andcleanMarkdown) to be package-level global variables. Added an entry to the.jules/bolt.mdjournal to document this optimization.🎯 Why:
regexp.MustCompileallocates 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 viago test -benchon the relevantnormalizeTopicSegmentandextractLearningsfunctions before and after the change, showing fewer allocs/op and reduced ns/op.PR created automatically by Jules for task 3976586067971291876 started by @lleontor705