Skip to content

Avoid encoding old values in complete element writeback - #673

Merged
nunoplopes merged 1 commit into
masterfrom
perfloop-pr-open-jy0nmh05jx
Nov 21, 2026
Merged

nunoplopes merged 1 commit into
masterfrom
perfloop-pr-open-jy0nmh05jx

Conversation

@perfloop

@perfloop perfloop Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Reads into typed buffers serialize destination elements again during writeback, even when incoming bytes replace the whole element. Skip that discarded work in the shared byte-write path while preserving bytes outside the written range.

In libcc2rs/src/reinterpret.rs, writeback handles a partial first element, assigns complete elements from incoming chunks, then handles a partial last element. Only the partial elements need their old bytes encoded. Empty affected ranges return after bounds validation. The single-element shortcut and variable-sized handling remain. All assignments still use assign_bytes, including array-length-preserving overrides. Ptr::with_slice_mut continues preparing the original bytes before invoking its callback.

Reading 3,032 bytes of README.md into boxed u64 storage measured median process CPU of 4,800 → 3,800 ns per seek/read cycle. The paired median change was −1,075 ns, with sequential median bounds of −1,750 to −500 ns from 22 complete pairs. Each invocation repeats 200,000 cycles with the same destination.

Results apply to warm file data and a reused destination. Initial destination preparation, native u8/i8 storage and variable-sized writes are unchanged.

The Cargo pointer and field tests passed in debug and release: 6 pointer tests and 1 field test per configuration, with no failures or ignored tests. Coverage in libcc2rs/src/rc.rs checks skipped old-value encoding, preserved boundary bytes, callback inputs and assignment overrides.

Case and evidence


Made by Perfloop.

@nunoplopes

Copy link
Copy Markdown
Contributor

Remove the benchmark and run ninja format to fix the CI failure.

Signed-off-by: Perfloop Agent <agent@perfloop.ai>
@perfloop
perfloop Bot force-pushed the perfloop-pr-open-jy0nmh05jx branch from e6d86fd to 2d014bc Compare November 20, 2026 20:22
@perfloop

perfloop Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

The benchmark and its Cargo registration have been removed, and the project formatter has been run. The writeback optimization and its regression test remain.

@nunoplopes
nunoplopes merged commit ba04beb into master Nov 21, 2026
9 checks passed
@nunoplopes
nunoplopes deleted the perfloop-pr-open-jy0nmh05jx branch November 21, 2026 08:37
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