#2518·WrenAI

Improve WASM SDK CI performance and cache reliability

Author: ttw225Created Jul 16, 2026Updated Sep 25, 2026
Labelsstale

Summary

WASM SDK CI currently takes approximately 17–29 minutes per run.

The observed latency comes from multiple independent causes rather than a single bottleneck:

  • production-oriented WASM optimization runs on every pull request;
  • intermittent Cargo cache misses add a cold-compilation penalty;
  • repository cache pressure increases the likelihood of those cache misses.

I plan to implement these improvements incrementally through separate, focused PRs. This issue is intended to track that work, share the overall context with maintainers and reviewers, and gather feedback on the proposed direction as the PRs are opened.

Evidence

Recent Build WASM + TypeScript SDK runs:

Scenario Cargo compile wasm-opt wasm-pack total
Warm cache 1:09 ~15:13 16:45
Cold cache 10:16 ~18:25 29:04

The measurements show two separate runtime costs:

  • wasm-opt -O adds approximately 15–18 minutes to every optimized build, even when the Cargo cache is warm.
  • A Cargo cache miss adds approximately 9–10 minutes of compilation.

The intermittent misses are consistent with repository cache pressure and eviction. Large PR-scoped Rust caches from other workflows account for most of the observed cache usage; the WASM workflow is primarily affected by that pressure rather than being its main source.

Because these problems are largely independent, they can also be addressed independently.

Why multiple PRs?

Although the changes all concern CI performance, they address different problems and have different risk profiles.

Keeping them in separate PRs makes each change easier to review, measure, and revert independently. It also allows the highest-value improvement to land without waiting for the broader cache-policy work.

Tracked work

  • Clean up caches from closed pull requests

    Remove caches associated with a pull request's merge ref after the PR closes, without checking out or executing PR-controlled code.

    This reduces long-lived repository cache pressure but does not directly change build behavior.

    PR: #2519

  • Add fast pull-request validation

    Use release-mode wasm-pack build --release --no-opt for pull requests. This skips the expensive Binaryen optimization pass while retaining release compilation, wasm-bindgen generation, type checking, and integration tests.

    Keep fully optimized builds on main and all publish paths. Reuse one deterministic 15 MiB gzip size check across those production paths.

    PR: #2520

  • Establish main-owned reusable Rust caches

    Provide trusted cache seeds from main for the relevant Rust workflows so PR jobs can primarily restore shared caches instead of producing many isolated PR-scoped target caches.

    Target-cache keys should account for the runner, exact compiler identity, and relevant Cargo inputs. A trusted cache-writing run must be able to create a fresh seed after a toolchain change.

    PR: planned

Suggested delivery order

  1. Closed-PR cache cleanup
  2. Fast pull-request validation
  3. Main-owned reusable caches

The cleanup change is suggested first because it is the smallest, lowest-risk, and most independent change—not because it provides the largest performance improvement.

Fast pull-request validation provides the largest immediate saving and has no dependency on the cleanup PR, so it may be delivered first or in parallel if faster payoff is preferred.

Completion criteria

This issue can be closed when:

  • closed pull requests no longer leave long-lived merge-ref caches;
  • pull requests use fast release-mode WASM validation without running wasm-opt;
  • fully optimized size validation runs on main, stable publish, and RC publish paths;
  • every publish path stops before publishing when the optimized artifact exceeds 15 MiB gzip;
  • the relevant Rust workflows have a trusted shared-cache strategy with compiler-aware cache keys;
  • follow-up measurements confirm that common pull-request feedback time is materially lower than the current 17–29 minute range.

Maintainer decision: size-check timing

At the time of writing, the main ruleset does not require status checks. Therefore, the current optimized size result on pull requests is advisory rather than an enforced merge gate.

The proposed default is:

  • fast --no-opt validation on pull requests;
  • fully optimized size validation on main and every publish path;
  • publishing blocked by any optimized size-check failure.

This does not remove an enforced pre-merge gate. It moves size-regression detection from pull-request time to the post-merge main build.

The current artifact is approximately 13.8 MiB gzip against a 15 MiB limit, leaving about 8% headroom. A failure on main should therefore be surfaced immediately and handled through a fast revert or remediation before publishing.

If pre-merge size enforcement is required instead, the alternatives are:

  1. keep a fully optimized pull-request job and accept the current 17–29 minute runtime; or
  2. run the optimized gate through a merge queue using merge_group.

Please confirm whether post-merge size detection on main is acceptable.

Possible follow-up

If optimized main or publish builds are still worth accelerating after the tracked work is complete, Binaryen settings, runner size, and DataFusion feature composition can be benchmarked separately.

That investigation is optional and is not required to close this issue.