Gemini CLI PR swaps unshift for push, fixing O(n²) cost in history truncation
Kaushik2210 · ghdev · 2026-09-26
A community PR on google-gemini/gemini-cli optimizes array reconstruction in truncateHistoryToBudget().
- Problem: The function walks messages newest-to-oldest to prioritize recent tool responses, then restores chronological order via per-part unshift() calls. Since front-insertion is O(n), total cost was O(H² + ΣPᵢ²), paid even for messages later summarized away.
- Fix: Append with push(), then reverse each parts array and the whole history once. Traversal order and all truncation decisions are unchanged — a behavior-preserving refactor.
- Tests: A new regression test locks in message/part ordering without truncation; 37/37 tests pass, eslint and tsc clean.
More from coding & agent
- Sydney Codex Community Buildathon set for Nov 14 with Cerebras-backed ultrafast compute track — paw_lean · 2026-11-11
- shadcn's improve hits 10k stars: let top models plan, cheap models execute code fixes — shadcn · 2026-11-11
- OpenAI open-sources Codex Security CLI and SDK for AI-driven vulnerability scanning and fixing — openai · 2026-11-11
- Claude Opus 5.5 runs an architecture search and finds AttnRes-Canon, a new top Transformer design — SonglinYang4 · 2026-11-11
- 5 research habits worth knowing: read papers backwards, reproduce first, wire coding agents via MCP — cneuralnetwork · 2026-11-11
- 'Adam can now do CAE': AI agent showcase in engineering simulation draws buzz — burhop · 2026-11-11