Skip to content

[wasm] Skip fetch integrity for fingerprinted assets by default (~25% of CoreCLR WebAssembly cold startup) #137529

Closed

Description

@davidwrighton

Summary

The WebAssembly loaders fetch every boot asset with fetch(url, { integrity: "sha256-..." }) unless disableIntegrityCheck is set. For CoreCLR WebAssembly that costs about 25% of cold startup on desktop and 16% on throttled mobile. Integrity checking was added to catch broken caching, not for security. Assets with fingerprinted (content-hashed) file names already give the same guarantee. I propose that, by default, the CoreCLR loader skip integrity for fingerprinted assets, and keep disableIntegrityCheck: false as an explicit way to keep it.

This is the change Javier Calvarro Nelson said he would accept in #102515 ("turn off integrity automatically when assets are fingerprinted, with an opt-in to keep it"). #102515 was closed because the data was too noisy. The Chrome measurements below are the data that discussion asked for.

Why integrity is expensive

The Fetch spec requires the entire body to be verified before the Response is returned. In Chrome that means:

  1. No streaming compilation. WebAssembly.instantiateStreaming only sees the response after the last byte has arrived and been hashed, so download and compilation never overlap. In a main-thread trace, each of the 67 Wasm modules was delivered in a single OnBytesReceived chunk. With integrity off, the same modules arrive in 130–200 small chunks and compile while downloading.
  2. Main-thread CPU. Chrome's IntegrityVerifier buffers the body and SHA-256-hashes it on the renderer main thread, then copies it again (EncodedFormData::Flatten).

Renderer main-thread profile, Chrome 157, from js_loaded to managed code ready:

Main-thread category Time Share of main thread
SRI SHA-256 hashing 158 ms 9.2%
SRI buffering and flatten copy 142 ms 8.3%
(for comparison) .NET Wasm code executing 180 ms 10.4%

CoreCLR pays more than Mono. It streams 67 Wasm modules: the native runtime, the composite R2R image, and one webcil module per assembly. Mono streams only dotnet.native.wasm.

Measurements

App: the Havit Blazor documentation app, CoreCLR WebAssembly with composite R2R. Each run used a fresh headless Chrome 157 with the cache cleared, variants in interleaved order, and a local HTTP/1.1 server. The variants differ only in the loader JavaScript.

Profile Variant Time to managed code Delta Faster than default
Desktop (15 rounds) default (integrity on) 1,279 ms - -
no integrity 952 ms -327 ms (-25.6%) 15/15
verify in JS (tee() plus crypto.subtle.digest) 1,175 ms -104 ms (-8.1%) 15/15
Mobile (10 rounds) default (integrity on) 6,449 ms - -
no integrity 5,392 ms -1,058 ms (-16.4%) 10/10
verify in JS 6,050 ms -398 ms (-6.2%) 10/10

Mobile is CDP 3x CPU throttling, 20/5 Mbps and 70 ms latency. Verifying in JavaScript recovers only about a third of the gain, because tee(), arrayBuffer() and the final digest still run on the main thread. The clean fix is not to need SRI for these assets.

A separate traced recapture (3 runs, perf sampling, js_loaded to managed ready) shows the same effect:

  • Main thread: about 18% fewer samples, roughly 295 ms less CPU per run.
  • SRI remainder of streaming compile: from 135–171 ms down to about 12 ms.

History: integrity was for caching, not security

  • Cache assemblies and wasm using content hashes aspnetcore#18859 (2020) added sha256 hashes to the boot manifest to drive a content-hash resource cache. It then switched from manual hash checks to fetch({ integrity }) for convenience. Its original design validated Wasm in the background "because streaming compilation only makes sense if you start it immediately"; native SRI lost that.

  • Blazor WebAssembly 3.2.0 breaks integrity of DLLs aspnetcore#21383: integrity failures caused by CRLF conversion, proxies, error responses and antivirus led to the BlazorCacheBootResources and disableIntegrityCheck opt-outs.

  • [wasm] Set default for disableIntegrityCheck to true #102515 (2024) proposed defaulting disableIntegrityCheck to true. It measured about 11% of startup CPU in Firefox going to copying and hashing. Javier's reply ([wasm] Set default for disableIntegrityCheck to true #102515 (comment)):

    we didn't use integrity for security purposes… The reason we used integrity was to break reliably on invalid caching… behind an HTTP proxy (corporate proxy, cloudflare, etc)… We always request blazor.boot.json with the no-cache directive, but we don't/can't do the same for other assets without taking a perf hit, so having the integrity check is important to block the app from potentially loading a mix of dlls.

  • For same-origin assets served over HTTPS, SRI adds no meaningful protection. Anyone who can tamper with the subresources can also tamper with the HTML or the boot config that carries the hashes.

Fingerprinting already covers the caching concern

A fingerprinted file name changes whenever the content changes, so a stale cached copy can never be served for the new URL. That is exactly the "mixed DLLs" problem integrity was guarding against.

Proposal

  • When disableIntegrityCheck is not set, skip integrity for assets the boot config marks as fingerprinted. Those are the assets with cache: "force-cache", or "reload" on retry.
  • Assets that are not fingerprinted keep integrity exactly as today. That covers WasmFingerprintAssets=false and custom hosting.
  • disableIntegrityCheck: false keeps integrity for all hashed assets (opt-in). disableIntegrityCheck: true keeps meaning "never".
  • Boot-config hashes are still emitted and still passed to loadBootResource and withResourceLoader callbacks.
  • Change only the CoreCLR loader, including its prefetch path. The Mono loader keeps its current behavior for now.

Follow-ups, out of scope here:

  • Ship non-composite webcil modules as one image. Once integrity is off, consolidating Havit's 65 small webcil modules into one image is projected to save another ~8% on desktop and ~2% on mobile. With integrity on, consolidation barely helps.
  • Ask browsers for streaming integrity verification, for deployments that must keep SRI.

Caveats

  • These measurements use a local server under WSL with fresh browser state; they are not from a real network.
  • DevTools CPU throttling slows the renderer main thread but not V8's background compile threads. Real phones are likely slower overall, so the saving there is probably at least as large in milliseconds.

Note

This issue was drafted with GitHub Copilot from local profiling experiments and GitHub history research.

Activity

  1. added
    arch-wasm
    on Nov 14, 2026
  2. dotnet-policy-service commented on Nov 14, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
    See info in area-owners.md if you want to be subscribed.

  3. added
    untriaged
    on Nov 14, 2026
  4. lewing commented on Nov 14, 2026

    @lewing
    Member
  5. added this to the 12.0.0 milestone on Nov 14, 2026
  6. removed
    untriaged
    on Nov 14, 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

    arch-wasmarea-Interop-mono

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions