Skip to content

perf(elf): preallocate fresh outputs and close the Wild performance gap #107

Open

Description

@zackees

Current status (after PR #108)

PR #108 merged as 92436c0; retained Phase A fresh ext4/XFS mmap fallocate; hosted Phase A vs Wild +6.3660% CI95 +5.2598..+7.1209; resolver cache rejected on four-core evidence (-1.4822% point) and is not in main; hard >=10% lower-CI gate remains unmet, so issue stays open; historical proposal/evidence below is retained for audit.

Context

The pinned Linux competition deletes the output path before every timed replay (ci/linux_linker_competition.py), so the frozen Clang final-link workload takes reld's fresh-file UnlinkAndReplace path rather than update-in-place. The locked LLVM llvmorg-22.1.8 corpus output is about 138 MiB on ext4 and currently takes the mmap path: crates/reld-core/src/fs.rs calls set_len and then MmapOptions::map_mut, with no preallocation or huge-page advice. The existing buffered-ext4 policy applies only at 256–512 MiB and must remain unchanged.

At origin/main 3dfc8fb1, five compilation-excluded, locked-corpus --no-fork --time diagnostic replays had these median spans:

Span Median
Link 170.56 ms
Shutdown 25.96 ms
Write output file 77.87 ms
Write data to file 61.68 ms

Shutdown is not comparable to the default fork-mode competition wall because the child signals completion before destruction. Excluding it leaves an approximately 144.60 ms active diagnostic transaction, of which output writing is material. Separate CPU/allocator investigation confirms allocator work is not a top hotspot, so changing allocators is not the next optimization target.

Published v2 evidence is reld 249.555 ms versus pinned Wild 262.095 ms. Reaching a 10.0% lead requires reld at or below 235.886 ms: a 13.670 ms / 5.48% reduction from the published reld result.

Relevant upstream prior art is wild-linker/wild#2468, head e822b94a3a36a89015b634ef332a757fb13392a0, merged as 2efdc81847a3cc9d9a9f0d4f4afa3ab4d698edac. Its author reports prior-art ext4 fresh-output results of roughly 23% wall reduction from fallocate, roughly 8% from hugepage advice, and roughly 36% combined. Those are upstream results, not reld measurements.

Measured scope correction

The first local isolation run rejected automatic THP: on this fresh-ext4 workload, fallocate-only was beneficial while automatic MADV_HUGEPAGE regressed. The longer independent diagnostic used default fork mode, fresh absent output before every trial, corpus cwd, LANG=C/LC_ALL=C, no compilation, three warmup rounds, and 24 measured samples per contender in a seeded randomized balanced Williams order. The candidate was cd5a30 with explicit --no-madvise-huge-pages, so it exercises auto-fallocate only; no reld-only flag was passed to Wild.

Variant Median wall time
origin/main baseline 134.004 ms
candidate, fallocate-only 125.170 ms
pinned Wild 0.9.0 128.569 ms

Candidate versus baseline improved by 6.592% (paired-bootstrap 95% CI 4.648%–8.651%). Candidate versus Wild improved only 2.643% (paired-bootstrap 95% CI 0.675%–3.986%); this does not meet the 10% target. Raw artifacts are /tmp/reld-107-wall-20260901T044304-1927309/ in the diagnostic environment. Baseline and candidate were two-run self-deterministic and raw-byte-identical (3a2654c7…353ff9e5); every timed output passed the exact native stdout/stderr/exit-code oracle. Wild was self-deterministic but has its own expected artifact hash.

The cgroup hierarchy was not delegated in that environment, so this diagnostic has no process-tree RSS conclusion. The supplied baseline/candidate source copies had no .git metadata; cd5a30 is the supplied candidate identity. This evidence evolves scope; it is not acceptance success.

Proposal

Two constrained, complementary changes are needed.

A. Fresh-output preallocation; THP opt-in only

  • Add explicit enable/disable controls for output preallocation and huge-page advice.
  • On Linux ext4/XFS fresh (UnlinkAndReplace) effective mmap outputs, auto-enable fallocate only. Keep automatic THP false.
  • Keep --madvise-huge-pages as explicit opt-in. It must fail clearly when mmap/setup/advice is unavailable or buffered mode was explicitly selected; --no-madvise-huge-pages remains an explicit disable.
  • Automatic fallocate is best-effort; explicit preallocation failure is clear. Keep update-in-place conservative, retain Btrfs/VFAT behavior and the 256–512 MiB buffered ext4 policy unchanged.
  • Carry settings through CommonArgs, file_writer::OutputConfig, and fs::OutputOptions, with syscall/advice implementation Linux-gated. Reuse existing nix and memmap2; add no dependencies.

B. Small, safe object-scoped relocation-resolution cache

  • Add only if required to clear the remaining gap; the fallocate-only evidence shows it is required.
  • Cache only successful, immutable Resolution values, keyed by the object-local SymbolIndex while relocating that object. Do not cache failures, and preserve failure diagnostics exactly.
  • No cache sharing across objects, debug emission, ordered table emission, or unrelated resolution consumers. Do not alter relocation ordering or output-writing semantics.
  • Bound the cache's memory by the current object's symbol index domain/lifetime; measure entries, capacity/bytes, and peak memory/RSS in final evidence rather than assuming a memory win.

Acceptance criteria

  • RED -> GREEN before implementation: parser/default/filesystem tests for both enable/disable controls; ext4/XFS fresh-mmap automatic policy (fallocate=true, THP=false); explicit THP override; Btrfs/VFAT and 256–512 MiB buffered behavior; update-in-place suppression; invalid hugepage-plus-buffered behavior; and explicit-versus-automatic failure handling.
  • RED -> GREEN cache tests: repeated relocations of one object/local SymbolIndex reuse the same successful immutable resolution; object boundaries cannot share entries; resolution errors are never cached and retain the unchanged diagnostic; debug/table paths are unaffected; cache memory is bounded and reported.
  • This is performance-only: no intended artifact change. Verify two-run self-determinism for both baseline and candidate, raw-byte identity to the pinned reld baseline and inherited Wild baseline where applicable, and the exact native stdout/stderr/exit-code oracle.
  • Use default hook-free release builds; compilation excluded; the locked corpus and pinned linker revisions/toolchain; fresh missing output on ext4; default fork mode; process-tree RSS; and the same-run Williams design with at least 2 warmups and 12 measured samples.
  • The final paired-bootstrap 95% CI lower bound must show reld at least 10.0% faster than pinned Wild, and there must be no statistically supported RSS regression. Do not weaken this gate.
  • Read and follow the Linux, Windows, and macOS platform guides before changing shared crates/reld-core, even though the new behavior is Linux-gated.

Decisions

  • Priority remains P0: fallocate-only captures a credible 4.648%–8.651% baseline improvement, but cannot by itself close the Wild gap.
  • THP is an opt-in diagnostic control, not an automatic default, because local fresh-ext4 evidence is negative.
  • Scope remains intentionally narrow: preallocation affects only fresh mmap output setup; caching is object-local successful relocation resolution only. perf(elf): parallelize full-LTO section population #80's ordered relocation/table emission remains intact.
  • No dependency change is in scope; use the repository's approved graph.

Related issues

  • #77 and #79 are prior Linux output-path performance work. They cover buffered/splice strategies, not fallocate, THP, or object-scoped resolution reuse; this issue preserves their retained buffered policy rather than reopening them.

Activity

  1. changed the title [-]perf(fs): preallocate fresh ext4/XFS mmap outputs and request THP[/-] [+]perf(fs): preallocate fresh ext4/XFS mmap outputs; opt-in THP[/+] on Sep 1, 2026
  2. zackees commented on Sep 1, 2026

    @zackees
    CollaboratorAuthor

    Scope correction: automatic THP is rejected locally

    The initial upstream-port scope auto-enabled both fallocate and MADV_HUGEPAGE for fresh ext4/XFS mmap outputs. Exact non-git baseline/candidate artifact and native-oracle gates passed, but preliminary fresh-ext4 default-fork isolation is negative for automatic THP.

    Interleaved diagnostic wall-time medians on the locked Clang final-link corpus were:

    Variant Median
    origin/main baseline 0.130s
    automatic fallocate + THP 0.160–0.165s
    both explicitly disabled 0.130s
    THP only (--no-fallocate-output-file) 0.150s
    fallocate only (--no-madvise-huge-pages) 0.120s

    This is diagnostic only: it has no cgroup process-tree RSS and is not the required 12-sample Williams/pinned-Wild acceptance run. It is nevertheless sufficient to reject making THP an automatic default on this host.

    Revised implementation decision:

    • auto-enable only fallocate for fresh ext4/XFS effective mmap outputs;
    • keep --madvise-huge-pages as an explicit opt-in with strict buffered/non-Linux/setup/advice errors;
    • retain --no-madvise-huge-pages, explicit fallocate controls, Btrfs/VFAT behavior, and buffered-output policy unchanged.

    The focused RED-to-GREEN policy test now requires automatic ext4/XFS setup (fallocate=true, THP=false) and proves explicit --madvise-huge-pages overrides that default.

  3. changed the title [-]perf(fs): preallocate fresh ext4/XFS mmap outputs; opt-in THP[/-] [+]perf(elf): preallocate fresh outputs and cache relocation resolutions[/+] on Sep 1, 2026
  4. zackees commented on Sep 1, 2026

    @zackees
    CollaboratorAuthor

    The longer independent fallocate-only diagnostic changes the scope, not the acceptance bar.

    With default fork mode, fresh absent output, frozen corpus cwd, no compilation, three warmup rounds, and 24 balanced/interleaved samples each, the candidate (cd5a30 --no-madvise-huge-pages) measured 125.170 ms median versus 134.004 ms baseline and 128.569 ms pinned Wild. That is +6.592% versus baseline (paired-bootstrap 95% CI +4.648% to +8.651%), but only +2.643% versus Wild (95% CI +0.675% to +3.986%). It therefore does not approach the required 10% lower-bound gate.

    Baseline/candidate artifacts were two-run self-deterministic and raw-byte-identical; every timed result passed the native oracle. The cgroup hierarchy was not delegated, so this run makes no RSS claim. Raw evidence: /tmp/reld-107-wall-20260901T044304-1927309/.

    Accordingly, automatic THP remains rejected locally: auto-enable only fresh ext4/XFS mmap fallocate, keep THP explicit opt-in, and add the smallest safe object-local successful-relocation-resolution cache needed to close the remaining gap. The issue now explicitly requires cache isolation/error/diagnostic/memory tests and retains the final paired-bootstrap >=10%-faster-than-Wild lower-bound and no-RSS-regression gates unchanged.

  5. zackees commented on Sep 1, 2026

    @zackees
    CollaboratorAuthor

    Phase-B status update (all results are local diagnostics; the hosted acceptance gate remains unchanged).

    • Phase-B commit 13d4161465e65e635b01b54d6f9c8a5631fdf5b6 is atop 4743b9b0b09715271bd466e49cdcb6206429dfea. Frozen-Clang raw artifact identity and exact native oracle passed.
    • In the 24-round candidate-vs-Wild diagnostic, Phase-B was +3.626% faster by median (paired bootstrap 95% CI +1.662% to +5.726%): a real local improvement, but well short of the required >=10% lower-confidence-bound gate.
    • Cache ablation measured +7.680% versus fallocate-only. Capacity variants 1024/2048/4096 showed no supported gain.
    • C1 per-section relocation-context hoist: +0.084% with CI crossing zero; rejected.
    • C2 writer invariants: -1.511% paired mean; rejected.
    • Immutable per-SymbolIndex ELF name-length cache: -2.095% (95% CI entirely negative) and +2.7–3.3 MiB diagnostic RSS; rejected.

    The issue remains open. Its paired-bootstrap >=10% lower-CI versus Wild requirement and no statistically supported RSS regression requirement are unchanged. Next investigation is a bounded scheduling/group sweep.

  6. zackees commented on Sep 1, 2026

    @zackees
    CollaboratorAuthor

    Authoritative hosted failure evidence from Linux linker competition run.

    • PR head: 4ee5d137aa2405e66cd37a7bd8a564ee681b74e8; hosted merge-ref evidence: f6c424f8587bc5fee4715fcc1954f543630cc51d.
    • Workload filesystem: ext4; host: 4 CPUs; 12 randomized/interleaved samples per contender; peak RSS backend: cgroup-v2 process-tree VmRSS sum.
    • Raw artifact identity and native oracle both passed (candidate and baseline raw output SHA-256 matched on every sampled run).
    • Wall versus Wild: +4.2255% (95% bootstrap CI +3.2964%..+4.7691%), which fails the hard >=10% lower-CI gate.
    • Wall versus baseline: +0.2488% (95% bootstrap CI -0.8161%..+1.1338%): no supported gain.
    • RSS versus baseline: -0.0932% (95% bootstrap CI -0.2811%..+0.0287%): no supported regression; the point estimate is worse.
    • RSS versus Wild: -0.1854% (95% bootstrap CI -0.2445%..-0.1272%): candidate worse.

    Evidence SHA-256:

    • report.json: 38b81167c92c5e22614097b7177f5e012eb1f83e65102f4f0c0a9f25c531f18f
    • raw-samples.jsonl: e4a4f4d1f62b4812496a2c21229dd3f59f3fa2ca5db655d89f760698e86c180a
    • provenance.json: 38cc1c868fc84c8e8bbb0580e80f05dfa25c356313524b32841f693dc646ddf7
    • render/competition.png: f43f7fad7401bec1db99c0f462dd62e5f537ab98cf2cd9f580e99f8163501ce0

    The PR remains draft. Do not merge; do not close #107.

  7. zackees commented on Sep 1, 2026

    @zackees
    CollaboratorAuthor

    Authoritative Phase-A-only hosted evidence: Linux linker competition run 33523506586, head 4743b9b0b09715271bd466e49cdcb6206429dfea versus baseline 3dfc8fb1c614485c82e8e59c17238b8c2411b0b8.

    The frozen LLVM/Clang final link ran on ext4 with 4 CPUs, default fork behavior, 12 balanced samples per contender, and cgroup-v2 process-tree RSS. Raw reld artifact identity and the native oracle passed.

    • Phase A vs baseline — wall: +1.7217% (95% bootstrap CI +0.6610%..+2.8553%); RSS: +0.0302% (95% CI -0.1025%..+0.0994%).
    • Phase A vs pinned Wild — wall: +6.3660% (95% bootstrap CI +5.2598%..+7.1209%); RSS: -0.0756% (95% CI -0.1741%..+0.0361%).

    Decision: fresh ext4/XFS mmap fallocate preallocation is retained and supported. The 512-slot resolver cache is rejected: the dedicated four-core 24-sample ablation was counterproductive by point estimate (Phase B vs Phase A -1.4822%, CI -4.7020%..+2.5056%). The hard >=10% Wild lower-CI gate still fails (Phase A lower bound: +5.2598%).

    The PR remains draft; do not merge or close #107.

  8. changed the title [-]perf(elf): preallocate fresh outputs and cache relocation resolutions[/-] [+]perf(elf): preallocate fresh outputs and close the Wild performance gap[/+] on Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions