Skip to content

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

Open
dhellmann wants to merge 1 commit into
python-wheel-build:mainfrom
dhellmann:bootstrapper-performance-by-claude
Open

perf(bootstrapper): reduce disk I/O with throttled stack writes, async graph writes, deferred build-order write#1249
dhellmann wants to merge 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.

…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 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: 58 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: 5dea9893-7860-4333-b679-78560133b13f

📥 Commits

Reviewing files that changed from the base of the PR and between fdf55b3 and 5821ed0.

📒 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
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