Skip to content

Reuse bounded matcher output capacities across batches - #1050

Merged
helly25 merged 1 commit into
mainfrom
perf/bounded-match-result-reuse
Nov 2, 2026
Merged

helly25 merged 1 commit into
mainfrom
perf/bounded-match-result-reuse

Conversation

@helly25

@helly25 helly25 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Reuse matcher output buffers within bounded retained capacities instead of reallocating them for every batch. A repeated 64-entry output batch uses 20% fewer allocation calls and about 25% fewer requested bytes on both macOS and Linux, while preserving output and error behavior.

AG;DR

Result ownership and reset contract

  • Reuse the existing ParallelResult slots. Workers mutate only their exclusively claimed private slot; the private entry evaluator receives its index and writes the pool's own state directly.
  • Before any new evaluation, release old text buffers whose capacity exceeds min(64 KiB, 1 MiB / current batch size). Shrinking/empty batches destroy truncated tails.
  • Clear reused text, reset selection status, and disengage content when a retained matched slot becomes unmatched. Preserve false/error/true transitions without stale output.
  • These limits apply to text capacity retained from a consumed batch. They do not truncate current output or cap status messages, vector metadata, or total process memory. Current records remain pool-owned and available until the next batch or destruction.
  • Keep input consumption, ordered result delivery, generation barriers, worker counts and admission policy. No input-recycling API, extra owner or new CLI flag is added.

Qualification and rejected controls

The committed decision report at docs/benchmarks/bounded-match-results-20261102.md and its lossless archive retain all source variants, source/executable hashes, fixture definitions, raw repetitions, scripts, allocation counters, and verification logs.

Four variants separate the mechanisms: baseline, direct writes while clearing/recreating records, bounded matcher reuse, and comparison-vector retention only. Adopt bounded matcher reuse. Reject the reset-only change as a separate optimization because it saves no output allocations. Reject comparison-vector retention: VFS range reads still return fresh owning strings, and keeping old result slots can prolong old small patch payloads without reusing their input buffers.

  • Coordinator-only ASan counters for a warmed 64-entry/1,028-byte-per-line batch: 320 -> 256 allocation calls on both hosts; requested bytes 264,704 -> 198,656 on macOS and 266,752 -> 200,192 on Linux. Setup, inputs, warmup and assertions are outside recording. These are allocation traffic measurements, never sanitizer performance timings or net live memory.
  • Native timing: 61 cases x three sessions x four variants, discarded warmups, nine rotation-only rounds/fastest seven, independent output oracles. Linux uses tmpfs and 1/3/10-CPU affinity; macOS uses warm APFS without affinity enforcement.
  • Separate case-interleaved in-memory timing: 46 RE2 cells plus 16 comparison cells, three sessions, nine repetitions/fastest seven. Linux pins 1/4 CPUs; macOS uses worker allowances. Eight focused cases repeat both promising and slower/noisy controls.
  • Preserve slower samples. Original macOS large-output ten-file timing is +4.90%; focused confirmation is -1.42%. The macOS 1,000-file/four-worker filter control remains +1.66% in confirmation. Native worst selected medians are +2.69% on Linux and +1.63% on macOS.
  • The comparison-only control also changes unrelated matcher timings. Their cause is not established; do not attribute those gains to output-buffer reuse. Copied benchmark executables have no mutable project shared-library dependency.
  • Unstripped build outputs shrink by 16 bytes on macOS and 2,328 bytes on Linux. No universal throughput or total-memory improvement is claimed.

Validation

  • Complete core/extension release suites pass 306/306 on both hosts; Linux uses required-FUSE integration.
  • Focused macOS ASan, Linux TSan, and final retained-slot regression release/ASan tests on both hosts pass. The final Linux regression also passes TSan.
  • Scoped local clang-tidy covers all five affected translation units, with the test-only arithmetic finding corrected and rechecked. Normal commit/push hooks enforce the current files; pushed-head GitHub CI remains required before merge.
  • Tests cover small-buffer reuse, aggregate and per-record reuse limits, giant output followed by a short inline tail, a retained matched slot becoming unmatched, empty-batch/growth transitions, and false/error/true status transitions without stale text.
  • Native wall/CPU time and child peak RSS remain in the evidence. First-output latency is not separately measured. Builds/lint/sanitizers never overlap timing on the same host.

Update TODO.md, docs/performance-analysis.md, CHANGELOG.md, and the release-site report mapping together. The exact evidence archive gets a narrow large-file-hook exception alongside the existing reports.

Based on merged #1049. The measured parent 8d96bc90fea5adb469b42e5e34a8be6a518f0f4b and merged main 901c8fea916124f4d0e195c5385f2a977b44093d have identical trees; the unpublished branch was synchronized before committing. O11 active-worker participation and budget-aware comparison source reuse remain separate.

@helly25
helly25 merged commit 2d615ea into main Nov 2, 2026
32 checks passed
@helly25
helly25 deleted the perf/bounded-match-result-reuse branch November 2, 2026 10:02
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