⚡ Optimize FeedbackConnection.items performance and robustness#4
⚡ Optimize FeedbackConnection.items performance and robustness#4
Conversation
- Replaced immutable bytes concatenation and slicing with `bytearray` and `del` to avoid $O(N^2)$ performance degradation. - Fixed a bug where processing would prematurely terminate if a received chunk was smaller than 6 bytes. - Updated loop condition to correctly handle 6-byte record headers. - Verified performance improvement: processing 16k tokens in a single chunk improved from 0.2447s to 0.0416s. Co-authored-by: Skywyze <7504109+Skywyze@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. |
This PR optimizes the
FeedbackConnection.itemsgenerator inapns.py.The original implementation used
buff += chunkandbuff = buff[bytes_to_read:], which led to quadratic time complexity due to repeated copying of the immutablebytesbuffer. By switching tobytearrayand usingextend()anddel, data accumulation and consumption are now significantly more efficient.Additionally, a bug was fixed where the loop would
breakif a chunk smaller than 6 bytes was received. This now correctly continues to fetch more data until enough is available to parse the record header.Performance impact:
All existing tests pass, and the partial chunk bug was verified fixed with a new test case.
PR created automatically by Jules for task 8078810807298983349 started by @Skywyze