Skip to content

perf(bootstrapper): reduce disk I/O with throttled stack writes, async graph writes, deferred build-order write#1249

Merged
mergify[bot] merged 1 commit into
python-wheel-build:mainfrom
dhellmann:bootstrapper-performance-by-claude
Jul 17, 2026
Merged

perf(bootstrapper): reduce disk I/O with throttled stack writes, async graph writes, deferred build-order write#1249
mergify[bot] merged 1 commit into
python-wheel-build:mainfrom
dhellmann:bootstrapper-performance-by-claude

Conversation

@dhellmann

Copy link
Copy Markdown
Member

Three file-write hotspots in the bootstrap loop were generating O(n²) disk I/O on the main thread:

  1. _record_stack_state was called on every loop iteration, serializing and writing the full stack to bootstrap-stack.json. Throttled to at most once every 5 seconds (force-flush in finalize()).

  2. add_to_graphwrite_to_graph_to_file() wrote the full graph on every dependency edge. Graph writes are now moved to a single-threaded background _write_pool via _write_graph_async(), keeping serialization on the main thread for a consistent snapshot but eliminating blocking I/O from the critical path.

  3. add_to_build_order rewrote build-order.json on every package. The disk write is removed entirely; data stays in _build_stack in memory and is written once in finalize().

Also renames write_to_graph_to_file()write_graph_file() in WorkContext for clarity.

Tests updated to reflect deferred build-order write (call finalize() before reading the file) and the stack-write throttle. Two new tests added: one verifying the throttle suppresses rapid writes, one verifying finalize() drains the write pool and produces both output files.

@dhellmann
dhellmann requested a review from a team as a code owner July 10, 2026 21:31
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@dhellmann, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 472ec2f1-5d97-4234-a145-a492ee43add0

📥 Commits

Reviewing files that changed from the base of the PR and between 414e606 and 88cf757.

📒 Files selected for processing (4)
  • src/fromager/bootstrapper/_bootstrapper.py
  • src/fromager/context.py
  • tests/test_bootstrapper.py
  • tests/test_context.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mergify mergify Bot added the ci label Jul 10, 2026

@rd4398 rd4398 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks really good! I added few comments / suggestions

Comment thread src/fromager/bootstrapper/_bootstrapper.py
Comment thread tests/test_bootstrapper.py
Comment thread src/fromager/context.py Outdated
…c graph writes, deferred build-order write

Three file-write hotspots in the bootstrap loop were generating O(n²)
disk I/O on the main thread:

1. `_record_stack_state` was called on every loop iteration, serializing
   and writing the full stack to bootstrap-stack.json. Throttled to at
   most once every 5 seconds (force-flush in `finalize()`).

2. `add_to_graph` → `write_to_graph_to_file()` wrote the full graph on
   every dependency edge. Graph writes are now moved to a single-threaded
   background `_write_pool` via `_write_graph_async()`, keeping serialization
   on the main thread for a consistent snapshot but eliminating blocking I/O
   from the critical path.

3. `add_to_build_order` rewrote build-order.json on every package. The
   disk write is removed entirely; data stays in `_build_stack` in memory
   and is written once in `finalize()`.

Also renames `write_to_graph_to_file()` → `write_graph_file()` in
`WorkContext` for clarity.

Tests updated to reflect deferred build-order write (call `finalize()`
before reading the file) and the stack-write throttle. Two new tests
added: one verifying the throttle suppresses rapid writes, one verifying
`finalize()` drains the write pool and produces both output files.

Co-Authored-By: Claude <claude@anthropic.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
@dhellmann
dhellmann force-pushed the bootstrapper-performance-by-claude branch from 5821ed0 to 88cf757 Compare July 17, 2026 19:54
@dhellmann

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@rd4398 rd4398 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good! Thanks

@mergify

mergify Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@mergify
mergify Bot merged commit 4c18163 into python-wheel-build:main Jul 17, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants