Repository navigation
Python: perf(core): fast path empty incoming messages in filter_new_messages - #8697
Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
Conversation
Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com>
|
Thank you for proposing this change. I am closing this PR for now because it has no linked issue, and I could not find an issue covering this specific problem. Our contribution guidelines ask contributors to create or reuse an issue and discuss the approach before nontrivial changes (with an exception for trivial changes). The repository PR template asks for Motivation & Context, Description & Review Guide, a Related Issue linked with a closing keyword such as |
In _sessions.py, filter_new_messages determines which messages in an incoming turn are new relative to existing history.
When incoming was empty while existing contained messages, the function still computed hashes for every message in existing history, allocated existing_set, and evaluated slice comparisons before returning an empty list. In sessions with longer conversation histories, this caused unnecessary serialization and hashing overhead on empty turns.
This PR adds an immediate if not incoming: return [] early exit to filter_new_messages. I also added unit tests covering this function in test_sessions.py.