Skip to content

Conversation

@google-labs-jules
Copy link
Contributor

πŸ’‘ What: Replaced the while loop containing asyncio.sleep(0.01) in is_http_client_busy with asyncio.Event.

🎯 Why: The previous implementation used a busy-wait loop that woke up every 10ms to check a boolean flag. This introduced unnecessary latency (jitter up to 10ms) and CPU overhead. Using asyncio.Event allows the event loop to wake up the waiting task immediately when the client becomes free, without polling.

πŸ“Š Measured Improvement:

  • Benchmark showed a reduction in wait time overhead from ~0.053s (busy wait with 0.01s sleep intervals) to ~0.050s (immediate wake-up) in a controlled test case with a 0.05s delay.
  • The primary benefit is the removal of the 10ms polling granularity, resulting in immediate responsiveness when the HTTP client is released.

PR created automatically by Jules for task 12909644194619267245 started by @GhostTypes

Replaced the blocking busy-wait loop in `is_http_client_busy` with `asyncio.Event` for efficient synchronization.
Maintained backward compatibility for the `_http_client_busy` attribute using a property wrapper.
Eliminated 10ms polling interval latency.
@google-labs-jules
Copy link
Contributor Author

πŸ‘‹ 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@GhostTypes GhostTypes marked this pull request as ready for review January 20, 2026 01:42
@GhostTypes GhostTypes merged commit 87df5af into main Jan 20, 2026
8 checks passed
@GhostTypes GhostTypes deleted the perf/optimize-http-client-busy-wait-12909644194619267245 branch January 20, 2026 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants