Skip to content

perf(driver): eliminate tree-shake double-decode, chunk par_map, and optimize V3 cache-hit path - #473

Merged
CommaBot merged 1 commit into
mainfrom
feat/wave-3d-37-treeshake-v3-speed
Dec 6, 2026
Merged

CommaBot merged 1 commit into
mainfrom
feat/wave-3d-37-treeshake-v3-speed

Conversation

@CommaBot

@CommaBot CommaBot commented Dec 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Driver- and oracle-only compilation speedups targeting tree_shake + decode and the V3 cache-hit path, plus closing all 5 P3 follow-ups from #466. No changes to crates/beamc-core/**, crates/beamrt/**, or proofs/**.

Performance optimizations (crates/beamc-driver/**)

  1. Eliminate double .beam decoding after tree-shaking (treeshake.rs, module_reflection.rs, lib.rs, main.rs):
    • Add tree_shake_beams_with_decoded returning the already-decoded BeamModules for kept modules (background-dropping pruned BeamModules and ModuleIndex tables), and reuse them directly in decode_with_func_masks without decoding all kept .beam files a second time.
    • Replace mfa_to_func: HashMap<(String, u32), usize> with HashMap<String, Vec<(u32, usize)>> (lookup_mfa) to eliminate per-lookup String allocations during the tree-shake BFS.
    • Lazily build label_pos inside extract_module_index only when OP_TRY or local OP_CALL is encountered.
  2. Chunked par_map (pipeline.rs):
    • Replace per-element cursor.fetch_add(1) + full-element sort_unstable_by_key with safe chunked work-stealing (chunk = 64 for large inputs), sorting only chunk headers and avoiding O(N log N) moves of large R values.
  3. Allocation-free chunked wf_check_par and fused V3.check_final (pipeline.rs):
    • Eliminate per-call idx: Vec<usize> + Result vector allocations in wf_check_par while preserving exact first-error-in-function-order semantics.
    • Fuse V3.check_final (wf::check_function, verify_function, soft_rt_ok_one) into a single chunked parallel pass with cache-line-padded AlignedAtomicUsize to avoid false sharing.
  4. Parallel pack.get in v3_plan and par_scalar shell refresh (pipeline.rs):
    • Move pack.get(&key) inside par_map in v3_plan.
    • Skip redundant refresh(ro) on freshly constructed Shell::new(ro) instances in par_scalar, raise CHUNK to 64, and skip all-cached chunks when skip.is_some().

Follow-ups from #466 (5 P3s)

  • P3-1 (cas.rs): Manual impl Hash for CacheKey (state.write(&self.0)) + cache_key_hasher_distinct_keys unit test.
  • P3-2 (lib.rs): Replace (use_oracle && cache.is_some()).then(...) with cache.filter(|_| use_oracle).map(...).
  • P3-3 (lib.rs): Extract scan_function_reachability and add prune_unreachable_functions_matches_core_callgraph guardrail test against beamc_core::opt::callgraph::{address_taken, callees}.
  • P3-4 (beamc-oracle/src/type_infer.rs): Remove debug_assert_eq! at TailCallDirect so malformed SSA does not panic in debug builds before wf_check_par.
  • P3-5 (beamc-oracle/src/type_infer.rs): Expand bsp_type_infer_deterministic_across_thread_counts to 339 functions (256 roots + 80 mid-layer forwarders + merge + mutual recursion) across 1, 2, 4, and 8 threads.

Verification

  • ./scripts/check-aeneas-subset.sh — PASS
  • ./scripts/check-beamrt-ssot.sh — PASS
  • cargo clippy --workspace --all-targets -- -D warnings — PASS (0 warnings)
  • cargo test -p beamc-core -p beamc-oracle -p beamc-driver — PASS (0 failed)
  • Interleaved 4-thread A/B on a 7,377-module tree-shaken OTP release (byte-identical output across cold, single-module warm R1/R2, and no-op warm2):
    • Cold: 31,207 ms -> 28,738 ms (-2,469 ms, -7.9% wall; tree_shake + decode 1,220.5 -> 684.0 ms, -44.0%)
    • Single-module warm1 R1 (Base -> New): 24,954 ms -> 22,027 ms (-2,927 ms, -11.7% wall; V3.facts -29.9%, V3.fold -18.1%, V3.check_stages -26.6%, V3.check_final -6.4%)
    • Single-module warm1 R2 (New -> Base): 15,414 ms -> 14,304 ms (-1,110 ms, -7.2% wall; tree_shake + decode 1,145.9 -> 698.4 ms, -39.1%; V3.facts -17.6%, V3.fold -13.0%, V3.check_stages -14.7%, V3.check_final -7.3%)
    • No-op warm2: 696 ms -> 407 ms (pre-treeshake hit + link hit)
    • Byte identity: BASE_EQ_NEW = YES, TS_WARM_IDENTICAL = YES

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@CommaBot
CommaBot merged commit 38da318 into main Dec 6, 2026
3 checks passed
@CommaBot
CommaBot deleted the feat/wave-3d-37-treeshake-v3-speed branch December 6, 2026 01:31
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.

2 participants