⚡ Bolt: Optimize Embedded Corpus Lookup and Allocations#187
Conversation
- Add `byCategory` index to `EmbeddedCorpus` for O(1) `GetByCategory` lookups (was O(N)). - Add `AppendAll` method to `EmbeddedCorpus` to avoid intermediate slice allocation. - Pre-allocate `allAtoms` slice in `JITPromptCompiler.collectAtomsWithStats` to reduce reallocations. Benchmarks: - `GetByCategory`: ~11x faster (3336ns vs 37953ns) - `AppendAll`: ~34x faster than `All` (182ns vs 6233ns) with 0 allocations. Co-authored-by: theRebelliousNerd <187437903+theRebelliousNerd@users.noreply.github.com>
|
👋 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. |
📝 WalkthroughWalkthroughThis PR introduces performance optimizations to the prompt atom corpus handling: a pre-built category index for O(1) lookups in atoms.go and a preallocated buffer approach in compiler.go that leverages a new AppendAll method to reduce memory reallocations during corpus collection. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
⚡ Bolt: Optimized Embedded Corpus Lookup and Allocations
💡 What:
byCategorymap index toEmbeddedCorpusto replace O(N) iteration inGetByCategory.AppendAllmethod to append atoms directly to a destination slice, avoiding the allocation of an intermediate slice inAll().collectAtomsWithStatsto pre-allocate theallAtomsslice based on corpus count to prevent slice resizing.🎯 Why:
GetByCategoryandAll(viacollectAtomsWithStats) are called frequently during prompt compilation.GetByCategorywas iterating the entire map (O(N)), which is slow for large corpora.Allwas allocating a full slice copy that was immediately appended to another slice, creating unnecessary garbage.📊 Impact:
GetByCategoryis ~11x faster (3.3µs vs 37.9µs).AppendAllis ~34x faster thanAll(182ns vs 6.2µs) and eliminates 8KB allocation per call (for 1000 atoms).🔬 Measurement:
go test -bench(benchmarks run locally and results documented).PR created automatically by Jules for task 776668771632516532 started by @theRebelliousNerd
Summary by CodeRabbit