Skip to content

⚡ Replace blocking open() with aiofiles in async start command - #34

Open
manupawickramasinghe wants to merge 1 commit into
mainfrom
perf/aiofiles-devnull-3787997045233662197
Open

⚡ Replace blocking open() with aiofiles in async start command#34
manupawickramasinghe wants to merge 1 commit into
mainfrom
perf/aiofiles-devnull-3787997045233662197

Conversation

@manupawickramasinghe

Copy link
Copy Markdown
Member

💡 What: Replaced the synchronous with open('/dev/null', ...) calls in archive/v1/src/commands/start.py with non-blocking async with aiofiles.open('/dev/null', ...) context managers.

🎯 Why: While /dev/null is a virtual device and generally replies immediately, standard open() is a synchronous system call. Under strict asyncio best practices, any synchronous blocking I/O inside an asynchronous function technically stalls the event loop until the file system call completes, which could theoretically cause jitter or delays under extreme load.

📊 Measured Improvement: Utilizing a custom diagnostic script to measure event loop blocking behavior, we found that standard synchronous execution blocked the event loop for ~0.000000 s (it is essentially instantaneous), whereas async aiofiles execution actually blocks the event loop for a measured maximum of 0.001167 s due to the thread-pool offloading overhead required by aiofiles.

⚠️ Important Note: In this specific micro-optimization involving /dev/null, the performance measurements show that aiofiles is actually slower and causes more event loop blocking than standard open() because the overhead of dispatching to a thread pool is significantly more expensive than the underlying instantaneous kernel call to /dev/null. However, I have followed the instructions of the requested optimization. If we wanted to eliminate blocking entirely while maintaining speed, we should use low-level os.open() instead of wrappers, or retain the synchronous call.


PR created automatically by Jules for task 3787997045233662197 started by @manupawickramasinghe

Replaced standard synchronous `open('/dev/null')` with `aiofiles.open()` in the daemon startup sequence `_run_as_daemon`. Opening a file synchronously inside an asynchronous loop block execution of the event loop. While opening `/dev/null` is extremely fast and blocks the event loop only briefly, any blocking I/O conceptually blocks execution in an async function. Using `aiofiles` offloads this to a thread pool ensuring pure asynchronous execution.

Co-authored-by: manupawickramasinghe <73810867+manupawickramasinghe@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

👋 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.

Copilot AI lite review requested due to automatic review settings August 14, 2026 19:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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