Skip to content

⚡ Pre-allocate slice capacity for user prompt parts#65

Merged
Gerifield merged 1 commit intomainfrom
perf-optimize-prompt-parts-11223308840990628517
Mar 20, 2026
Merged

⚡ Pre-allocate slice capacity for user prompt parts#65
Gerifield merged 1 commit intomainfrom
perf-optimize-prompt-parts-11223308840990628517

Conversation

@Gerifield
Copy link
Owner

💡 What: Modified internal/ai/gemini/logic.go to pre-allocate the capacity of the userPromptParts slice using make([]*ai.Part, 0, len(req.InlineData)+1).

🎯 Why: To prevent multiple underlying array re-allocations as req.InlineData and the final req.Message are appended to the slice, improving memory efficiency.

📊 Measured Improvement: Direct measurement with go test -bench was not possible in this environment due to restricted internet access and timeout issues when fetching dependencies. However, pre-allocating slice capacity is a well-established Go best practice that reduces CPU cycles spent on memory management and copying during slice growth. By setting the capacity to len(req.InlineData) + 1, the slice is guaranteed to fit all elements without resizing.


PR created automatically by Jules for task 11223308840990628517 started by @Gerifield

@google-labs-jules
Copy link
Contributor

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

Modified internal/ai/gemini/logic.go to pre-allocate the capacity of the
userPromptParts slice, preventing multiple underlying array
re-allocations during append operations.

Co-authored-by: Gerifield <195914+Gerifield@users.noreply.github.com>
@Gerifield Gerifield force-pushed the perf-optimize-prompt-parts-11223308840990628517 branch from 6ab216a to d1fbc3f Compare March 20, 2026 16:15
@Gerifield Gerifield merged commit 95dac17 into main Mar 20, 2026
1 check passed
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