Skip to content

perf: reduce byte-word shingle allocation and copying - #1059

Merged
helly25 merged 24 commits into
mainfrom
perf/borrow-normalized-shingles
Nov 3, 2026
Merged

helly25 merged 24 commits into
mainfrom
perf/borrow-normalized-shingles

Conversation

@helly25

@helly25 helly25 commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Word-similarity comparisons now avoid redundant word-window strings and repeated work for byte-identical content while preserving the existing exact scores. The selected implementation improves larger native similarity workloads on both macOS and Linux; rejected alternatives and slower controls remain documented.

AG;DR

Implementation and scope

  • O21a: return early for byte-identical input after the existing width-zero check; preserve staged owning words/keys for one-word shingles and remove their redundant singleton join. Wider windows borrow from two final, locally owned normalized buffers. Sets die before their owners; no views survive a call or refer into a moved small string.
  • Preserve ASCII folding, opaque bytes >= 0x80, separators, unique shingles, empty/short input behavior, Jaccard scoring and rounding. Clarify the existing byte-oriented contract rather than implying Unicode decoding.
  • Keep key iteration by reference. No new flags, worker policy, lock, shared cache, exception mechanism, external dependency, or license obligation. Cross-entry reference reuse/indexing remains O21b, not implemented here.
  • Add an independent allocating reference, boundary/long-word/width cross-product tests and 1,000 seeded opaque-byte pairs; extend common in-memory whole-engine benchmark scenarios.

Evidence and tradeoffs

docs/benchmarks/byte-shingle-representations-20261102.md and its 2.75 MB compressed lossless artifact retain exact sources, compiler/link commands, samples, oracles, setup failures and rejected prototypes. The original all-view one-word path regressed larger macOS kernels by 26-33%; direct word-to-set insertion was also not selected. The final staged path is separately measured.

Per platform: 66 native cases x 3 sessions, 51 whole-engine/kernel cases x 3 sessions x 2 variants, plus ten native cases x 5 confirmation sessions and eight memory cases x 3 confirmation sessions with an identical-baseline participant. Each uses a discarded warmup and rotating nine-round/fastest-seven measurements. Linux tmpfs/affinity and macOS warm APFS remain separate contracts. Complete native output is checked against an independent oracle; timings never overlap builds, lint, sanitizers or allocation diagnostics on the host.

Confirmed 10,000-file nearby/strict word cases reduce native elapsed time by about 18-26% on macOS and 46-49% on Linux. Disjoint one-word confirmation is about 4.5% faster on macOS and 27.5% on Linux. Exact-content gains are separate. Preserve listing controls: initial Linux listing was +8.21%, confirmation +2.36% versus an identical-baseline repeat of +0.95%; small near controls also show about +1.2%. These are not hidden or normalized away. Requested workers do not imply newly parallel similarity evaluation.

ASan allocation-hook counts are diagnostics only; no instrumented times are performance evidence. Wider nearby shingles cut thousands of allocation requests to roughly 130; macOS one-word allocation count increases slightly while requested bytes and release elapsed time decrease. Unstripped CLI size changes: Linux +8,664 bytes; macOS +176 bytes. Binary linkage remains system-only with no additional libraries.

Validation and dependency

  • Local development qualification: all 323 extension-enabled release tests pass on each platform, with Linux FUSE required; six focused ASan suites pass on each; six focused Linux TSan suites pass. Scoped clang-tidy and normal enforcing commit hooks pass. Normal enforcing push hooks are retained.
  • Timed parent d528de1 is tree-identical to main 6bebe94 after Aggregate ordinary comparison side totals directly #1057. This branch also includes isolated CI repair Free hosted Linux build space before LLVM extraction #1058; intervening parent changes touch only the cache action and its Python test, with no runtime, compiler/configuration, module or extension change. Its declared Bazel test was rerun successfully on both hosts after synchronization.
  • Free hosted Linux build space before LLVM extraction #1058 merged as c004bcc. This branch was immediately synchronized and pushed onto main with an identical runtime tree. Current post-retarget CI is required; local development results do not substitute for it.
  • The initial MSan run timed out in the new allocating-reference test at its default 60-second limit, without a sanitizer diagnostic. Give only that target the moderate timeout (300 seconds), preserving its complete 1,000-pair corpus and all checks. Normal enforcing commit/push hooks pass for this fix; replacement CI is running.
  • Register the report for release-site publication, update the performance inventory, preserve remaining O16b-O22 follow-ups, and track series-wide stable chart ordering separately; no chart rendering change is included.

Merge sequencing: explicitly held by the user while #1065 is attempted first. Auto-merge is disabled; do not merge this PR automatically.

Base automatically changed from ci/free-llvm-extraction-space to main November 2, 2026 22:26
@helly25
helly25 merged commit 22702c3 into main Nov 3, 2026
32 checks passed
@helly25
helly25 deleted the perf/borrow-normalized-shingles branch November 3, 2026 01:24
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