Skip to content

Reuse budgeted native comparison cursor buffers - #1047

Merged
helly25 merged 1 commit into
mainfrom
perf/cursor-owned-read-buffers
Nov 2, 2026
Merged

helly25 merged 1 commit into
mainfrom
perf/cursor-owned-read-buffers

Conversation

@helly25

@helly25 helly25 commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Reuse native comparison buffers across file chunks, reducing allocation traffic and making large complete comparisons faster on macOS and Linux. Keep existing archive and decoder behavior and source-budget limits.

AG;DR

  • O07 from docs/performance-analysis.md and TODO.md; Avoid redundant zeroing in native bounded range reads #1046 is merged. Replayed the single O07 commit onto current main 7c0f507f7c815146a9b746e40269377dbc768b37 and immediately pushed synchronization. Git reports no tree difference from the qualified pre-squash head; required CI now runs in the main-base context. Evidence retains the exact original measurement parent rather than relabeling old samples.
  • Add an optional ReadStream::ReadInto(span<char>) capability. Only the read-only host adapter opts in. Unsupported streams neither allocate/copy nor consume input. The existing owning Read interface remains unchanged.
  • Each comparison cursor owns one reusable 64 KiB buffer under its existing source-budget reservation; storage dies before the reservation. Preserve short non-EOF reads, EOF, errors, metadata-sized comparisons and left-read-before-right-open ordering. Reject invalid returned byte counts.
  • Clear only the initial buffer allocation. An entirely uninitialized prototype repeatedly regresses Linux ten-worker early differences (6.88%, then 8.84%). Keep that data rather than asserting a guessed page-fault/allocator explanation.
  • Compile separate native and legacy loops. The initial combined loop regressed one unchanged macOS memory-source control 29.36%; the refined version removes that large penalty. Legacy-left/native-right pairs conservatively retain owned reads; mixed native-left/legacy-right pairs retain fallback bytes only for that comparison step. No archive worker/admission expansion.
  • No new user flags, dependencies, stats, locks, threads, shared owners, global pool or exception wrappers. File I/O stays in the VFS adapter; test writes use authorized temporary outputs.

Evidence and limits:

  • docs/benchmarks/cursor-owned-read-buffers-20261102.md publishes initial/refined variants, all raw native and fallback samples, source/binary hashes, scripts and allocation-control logs/XML. Source snapshots match the measured production implementation.
  • 10,800 native invocations across both hosts including discarded warmups. Three sessions, nine interleaved rounds, fastest seven, independent exact status/path oracles. Native 1/3/10 workers; 10/100 large files and 1,000 64 KiB controls. Linux tmpfs plus CPU affinity; macOS warm APFS without affinity. Release LLVM 23 + ThinLTO, with no concurrent build/diagnostic work during timing.
  • Refined 100-file complete 1 MiB comparisons improve about 14% with one worker and 9% with three on macOS, and 5-10% on Linux. Worst native paired medians remain visible: +0.93% macOS / +3.37% Linux. Memory fallback controls retain their separate established 1/4-worker kernel contract and small regressions. No claim every command, archive throughput or high-worker small population improves.
  • Isolated ASan diagnostics measure counts only: sixteen-chunk comparisons use 13 allocations instead of 43 on both hosts; total requested bytes fall from about 2.10 MB to 132 kB. This is allocation traffic, not a claim of the same reduction in peak RSS. Old-code diagnostic fails as expected, selected code passes; fixture creation and assertions are outside recording.

Validation:

  • Both fully enabled release/extension suites pass 305/305; Linux requires functional FUSE integration.
  • Final three focused ASan targets pass on macOS; final comparison/read-source MSan tests and constant-allocation ASan diagnostic pass on Linux.
  • Regression tests cover caps, zero/short reads, offsets, EOF, unused tails, multiple chunks, mixed capabilities, invalid counts, error ordering, and budget exhaustion/release.
  • Raw-pointer and host-I/O checks pass. Local clang-tidy explicitly covers 117 affected units: the current scope selector misses the Bazel include_prefix alias for read_source.h, so a temporary helper derives the aliases from BUILD declarations. TODO records the generic tooling fix; no hand-maintained alias catalog is added to production.
  • Local affected-header lint completed: 117/117 passed. Normal commit and push hooks passed; current-head PR CI is running. The additive virtual method requires rebuilding statically linked modules; no stable external binary ABI is promised.

Base automatically changed from perf/uninitialized-read-buffers to main November 2, 2026 04:25
@helly25
helly25 force-pushed the perf/cursor-owned-read-buffers branch from cdaae0e to d2ff56b Compare November 2, 2026 04:26
@helly25
helly25 merged commit c14d39c into main Nov 2, 2026
61 of 63 checks passed
@helly25
helly25 deleted the perf/cursor-owned-read-buffers branch November 2, 2026 05:40
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