⚡ Bolt: Optimize socket buffer JSON parsing#3
Conversation
💡 What: - Optimized `_handle_client` loop in `addon.py` to only attempt JSON parsing when the buffer likely contains a complete object (ends with `}`). - Optimized `_get_aabb` to avoid intermediate list allocations and unnecessary `zip/map` calls. 🎯 Why: - Previous implementation attempted to decode and parse the accumulating buffer on every received chunk (8KB). For large payloads (e.g., 1MB), this resulted in O(N^2) complexity for decoding/parsing, causing significant CPU usage and latency. - The AABB calculation was creating multiple temporary lists for 8 corners, which is a micro-optimization but cleaner. 📊 Impact: - Reduces parsing time for large fragmented messages by ~14x (benchmark: 0.14s -> 0.01s for 1MB payload). - Reduces memory churn during large transfers. 🔬 Measurement: - Verified with `benchmark.py` simulating chunked delivery of 1MB JSON. - Validated logic correctness with `tests/test_server_logic.py` ensuring partial packets are handled correctly.
|
👋 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 implements a performance optimization for the socket server loop in
addon.py.Changes:
buffer.strip().endswith(b'}')before attemptingjson.loads. This prevents expensive UTF-8 decoding and JSON parsing attempts on obviously incomplete data chunks, significantly improving performance for large payloads (e.g., asset metadata or generated models)._get_aabbto use an in-place min/max update loop instead of creating intermediate lists and usingmap(min, zip(...)), reducing overhead.Verified with a benchmark script showing ~14x speedup for 1MB payloads and unit tests mocking the socket behavior.
PR created automatically by Jules for task 8056828557242498092 started by @hnethery