From 6c7e79eff6061d681b96ba06cd966a2f7a9a9625 Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Wed, 23 Oct 2024 03:36:14 -0400 Subject: [PATCH] Cap the size of the Supermaven states buffer (#19246) Caps the size of the Supermaven states buffer to 1000 elements. Previously, the buffer would grow unbounded so for long sessions the number of states that the Supermaven autocomplete provider maintains can be quite large. In practice, states that are sufficiently old are so unlikely to be visited again that we can regenerate the completion. Thus, we can cap the buffer to 1000 elements. Release Notes: - N/A --- crates/supermaven/src/supermaven.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/supermaven/src/supermaven.rs b/crates/supermaven/src/supermaven.rs index 68a55504028f70d14a1d3a1c9d905a51ec02480e..152a41c3be250860a6c8aa2df28484392cada796 100644 --- a/crates/supermaven/src/supermaven.rs +++ b/crates/supermaven/src/supermaven.rs @@ -147,6 +147,14 @@ impl Supermaven { updates_tx, }, ); + // ensure the states map is max 1000 elements + if agent.states.len() > 1000 { + // state id is monotonic so it's sufficient to remove the first element + agent + .states + .remove(&agent.states.keys().next().unwrap().clone()); + } + let _ = agent .outgoing_tx .unbounded_send(OutboundMessage::StateUpdate(StateUpdateMessage {