Skip to content

Avoid redundant zeroing in native bounded range reads - #1046

Merged
helly25 merged 2 commits into
mainfrom
perf/uninitialized-read-buffers
Nov 2, 2026
Merged

helly25 merged 2 commits into
mainfrom
perf/uninitialized-read-buffers

Conversation

@helly25

@helly25 helly25 commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Read bounded host ranges directly into string storage, publishing only bytes returned by successful reads. Paired 64 KiB comparison workloads improve about 4-7% on both macOS and Linux while preserving EOF, short reads and errors.

AG;DR

  • O06 from docs/performance-analysis.md / TODO.md; synchronized onto main after Record rejected field lookup allocation experiments #1045 merged. Render lexical filename fields from borrowed path slices #1044 and Record rejected field lookup allocation experiments #1045 are included.
  • Use C++23 resize_and_overwrite only in LocalFs::ReadContentRange. Fill at most the requested length; publish only initialized bytes. Keep native offset checks, EINTR retry, short-read/EOF behavior and error statuses; close the read-only descriptor once after the callback.
  • The standard callback's required writable pointer has an explicit ABI annotation. No new public API, allocation pool, lock, extra stat, dependency, flag or exception cleanup is added. Existing VFS/budget boundaries stay intact.
  • Keep HostStream::Read unchanged. Its zeroing-removal prototype improves long one-worker reads but repeatedly regresses Linux ten-worker early differences (6.28%, then 8.76%). Preserve the rejected source/data and revisit cursor ownership/reuse under O07.
  • Add regressions for chunk/EOF boundaries, nonuniform byte patterns, zero/short/beyond-EOF requests, offsets, native errors and ownership of earlier chunks. Fixtures write only through the authorized temporary-output adapter.

Evidence:

  • docs/benchmarks/host-range-overwrite-20261102.md plus lossless archives retain all three phases: initial combined candidate, baseline/combined/range-only decomposition, and final range-only qualification on current parent 4e8d2bc (runtime includes merged main d546fcb).
  • 22,560 exact-output-checked fresh invocations including discarded warmups. Three sessions, nine interleaved rounds, fastest seven. File counts 10/100/1000, 4 KiB/64 KiB/1 MiB payloads, 1/3/10 workers. Identical/early/late differences plus size-only no-read controls.
  • Linux tmpfs and child CPU affinity; macOS warm APFS and worker allowance without affinity. LLVM 23 release + ThinLTO. An in-memory VFS would bypass these OS adapters, so native cached-file measurements are necessary.
  • Final principal 64 KiB cases improve roughly 4-7% on both hosts. Small cases stay near baseline. Preserve counterexamples: slowest paired median +0.83% macOS / +3.41% Linux in unchanged cursor/control shapes. No claim every invocation or streaming read improves.
  • Keep all source/binary hashes, raw repetitions, fixture/measurement scripts and native timing-helper source. Sanitizer time is never performance evidence.

Validation:

  • Final complete release/extension suites: 305/305 on both hosts, with working FUSE explicitly required on Linux. Initial-parent complete suites also passed 304/304.
  • Exact final focused ASan (macOS) and MSan (Linux): both local_fs_test and read_source_test pass.
  • Scoped local clang-tidy passes all three changed translation units. Raw-pointer and host-I/O policy checks pass.
  • Normal commit and push hooks passed for publication and synchronization. Current-head PR CI is recorded as it completes.
  • CI identified two uncovered lines in the defensive offset-addition overflow guard. A real host file cannot return bytes beyond the maximum representable off_t; retain the guard and explicitly exclude only that impossible host-file branch from coverage. This is a comment-only correction; measured runtime code is unchanged. Existing directory-read errors and exact offset-limit tests remain exercised. This change deliberately leaves cursor zeroing for the separately measured O07 ownership work.

Base automatically changed from docs/field-lookup-controls to main November 2, 2026 03:31
@helly25
helly25 force-pushed the perf/uninitialized-read-buffers branch from 55e0a06 to 08d4a56 Compare November 2, 2026 03:34
@helly25
helly25 merged commit 7c0f507 into main Nov 2, 2026
32 checks passed
@helly25
helly25 deleted the perf/uninitialized-read-buffers branch November 2, 2026 04:25
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