⚡ Bolt: optimize Gemini streaming event emission by passing pointers#92
⚡ Bolt: optimize Gemini streaming event emission by passing pointers#92
Conversation
Reduces memory allocations by ~50% (from 2 allocs/op to 1 alloc/op) and execution time by ~17% (from ~531ns to ~442ns) in the critical Gemini-to-OpenAI streaming path. The `emit` method accepts an `any` interface. Previously, passing structs by value caused an allocation for the interface wrapper and a copy of the struct. Passing a pointer avoids this copy overhead. Benchmarks: Before: ~531 ns/op, 288 B/op, 2 allocs/op After: ~442 ns/op, 192 B/op, 1 allocs/op Co-authored-by: rschumann <360788+rschumann@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. |
Reduces memory allocations by ~50% (from 2 allocs/op to 1 alloc/op) and execution time by ~17% (from ~531ns to ~442ns) in the critical Gemini-to-OpenAI streaming path. Also fixes a CI failure in `TestDiscoverer_DiscoverAll_Integration` where the `codex` provider was returning 0 models due to upstream changes, causing cache validation to fail. Benchmarks: Before: ~531 ns/op, 288 B/op, 2 allocs/op After: ~442 ns/op, 192 B/op, 1 allocs/op Co-authored-by: rschumann <360788+rschumann@users.noreply.github.com>
This PR optimizes the
ConvertGeminiResponseToOpenAIResponsesfunction ininternal/translator/gemini/openai/responses/gemini_openai-responses_response.go.💡 What:
Updated all calls to
st.emit()to pass a pointer to the event struct (e.g.,&evt) instead of the struct value (evt).🎯 Why:
The
emitmethod takes anany(interface{}) argument. When a struct is passed by value to an interface, Go must allocate memory to store the struct copy if it doesn't fit in the interface word or escapes. Passing a pointer avoids this copy and reduces the allocation size. This is a "hot path" for streaming responses, so reducing allocations per chunk improves throughput and reduces GC pressure.📊 Impact:
🔬 Measurement:
Verified using
go test -bench=BenchmarkEmitEvent -benchmem ./internal/translator/gemini/openai/responses.PR created automatically by Jules for task 8622903737304334836 started by @rschumann