Skip to content

Example optimization hunt#1762

Closed
preinlein wants to merge 1 commit intopaul.reinlein/selective-benchmarks-in-optimization-loopfrom
paul.reinlein/example-hunt
Closed

Example optimization hunt#1762
preinlein wants to merge 1 commit intopaul.reinlein/selective-benchmarks-in-optimization-loopfrom
paul.reinlein/example-hunt

Conversation

@preinlein
Copy link
Contributor

@preinlein preinlein commented Feb 11, 2026

What does this PR do?

Implements a zero-copy optimization for Cache::read_at in the block cache that significantly improves performance for reads that fit within a single block. When a read is contained within one block, the function now returns a slice of the existing Bytes instead of allocating a new buffer and copying data.

Motivation

This optimization dramatically improves performance for common read patterns in the logrotate_fs file generator:

  • 86.9% reduction in time for 1KiB reads (36.7ns → 4.8ns)
  • 99.5% reduction in time for 64KiB reads (1.02μs → 4.9ns)
  • No change for 1MiB reads that span multiple blocks (expected)

Related issues

N/A

Additional Notes

The PR also documents two optimization attempts in the optimization database:

  1. The successful zero-copy optimization for Cache::read_at
  2. A failed buffer reuse optimization for trace_agent::v04::V04::to_bytes that reduced memory allocation by 65.6% but showed no timing improvement because serialization cost dominates

The zero-copy approach works well because:

  1. Block data is already stored as immutable Bytes (reference-counted)
  2. Most reads are smaller than block size (256KiB blocks, typical reads 1-64KiB)
  3. The fast path check is a simple comparison
  4. The slow path (multi-block reads) maintains the original behavior

The full Claude run can be found here: https://drive.google.com/file/d/1mbgFAFuC5s2HwM3IhoNCgqZcmt7Ho7a2/view?usp=sharing

Copy link
Contributor Author

preinlein commented Feb 11, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@preinlein
Copy link
Contributor Author

Closing this as I don't want to merge these optimizations/optimization hunt results in yet (I've got more changes coming afterwards to make the reports consistent).

@preinlein preinlein closed this Feb 11, 2026
@preinlein
Copy link
Contributor Author

In case this gets missed in the PR description, the full claude run can be seen here: https://drive.google.com/file/d/1mbgFAFuC5s2HwM3IhoNCgqZcmt7Ho7a2/view?usp=sharing

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.

1 participant