Skip to content

perf(wasm): shrink the WASM from 4.61 MB to 3.93 MB (LC-2429) - #22

Merged
TaylorBeeston merged 10 commits into
mainfrom
perf/lc-2429-wasm-size
Nov 17, 2026
Merged

TaylorBeeston merged 10 commits into
mainfrom
perf/lc-2429-wasm-size

Conversation

@TaylorBeeston

@TaylorBeeston TaylorBeeston commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Jira: LC-2429

Shrinks the default DIDKit WASM from 4.61 MB to 3.93 MB raw, and from 1.23 MB to 1.06 MB at brotli-11 (−14.7% / −13.9%). It does that by dropping two things LearnCard doesn't use and that can't work in a browser anyway: the zcap exports, and did:webkey / did:onion / did:ion.

The first version of this PR also dropped JSON Schema validation and the schema.org / traceability contexts. Custard7 pointed out that the schema cut lets a signed, schema-invalid credential come back with errors: [] when the caller asks for the credentialSchema check, so Taylor decided to keep both. df41b05 and 32a36ab revert those two cuts, and e79fb2e reverts the matching SSI_REF bump in push_image.yml. Both workflows are back on main's ssi ref (9e2783f), so this PR doesn't depend on learningeconomy/ssi#17 anymore.

build raw brotli-11 Δ raw Δ brotli
main 35d0889 4,607,664 1,229,055
this PR 5b64be4 3,931,449 1,057,886 −676,215 (−14.7%) −171,169 (−13.9%)

Both come from wasm-pack 0.13.1 plus wasm-opt -Oz from Binaryen 124 with LearnCard's flags, on rustc 1.98.0, built from checkouts at the same path depth (panic paths end up in the binary, so path length moves the size by a few KB). Brotli-11 is from Node's zlib. Per cut, from my earlier rebuild on 82ef1d9: (a) −193,287 raw / −43,302 brotli, (b) −482,258 / −127,840.

What changed

(a) d325438: codegen-units = 1 in the workspace release profile, and didkit-wasm's default features drop invoke and delegate. Those features gate the 9 zcap exports, and LearnCard calls none of them. It calls 17 of the 35 exports, and all 17 are still there. Build with --features invoke,delegate to get the zcap exports back. I also gated the imports and helpers that only those exports use, so the default set, invoke,delegate, zcap and invoke each build cleanly with -Dwarnings. One side effect: codegen-units = 1 applies to every release build in the workspace (CLI, HTTP server, native libs). It should make them slightly smaller and might make release compiles a bit slower.

(b) f77cbb7: did:webkey, did:onion and did:ion become default features of the didkit crate. The CLI, HTTP server and C/Java bindings keep all three. didkit-wasm already uses default-features = false, so it drops them. None of them works in a browser today:

  • did:ion always fails with Missing Sidetree API endpoint.
  • did:onion sends plain HTTP to the .onion host.
  • did:webkey has no LearnCard callers and is the only reason the OpenPGP stack gets linked.

With this cut, all three return methodNotSupported in the WASM. pgp was also the only crate turning on x25519-dalek's static_secrets, which jwe.rs needs, so didkit-wasm now asks for that feature directly.

Docs (5b64be4): lib/web/README.md has a new "What the WASM build leaves out" section that lists the dropped zcap exports and the three dropped DID methods, plus how to get each back. The "DID methods" section from #21 now says those three return methodNotSupported. CHANGELOG.md gets matching Unreleased entries, including the new did-webkey / did-onion / did-ion features for anyone depending on didkit with default-features = false.

I also merged main (35d0889, #21) in. It merged cleanly; the only reason was to keep the README's DID methods section consistent with this PR.

Testing

  • cargo test --locked -p didkit-wasm --lib passes (4 tests, including fix(wasm): secp256k1 did:key in the WASM build (LC-2431) #21's secp256k1 round trip).
  • The built WASM still has the traceability context and the regex Unicode tables that JSON Schema validation needs. I checked by grepping the binary, and both were missing from the old (d) build.
  • Probe's smoke test in Node: Ed25519 CLR VP issue and verify, tampered VP rejected, did:ethr, did:tz, JWE round trip, static context load, live did:web resolve. All passed.
  • DID method check in Node: did:key (Ed25519, secp256k1, P-256), did:tz, did:ethr, did:pkh and did:jwk generate and resolve, a secp256k1 did:key VC issues and verifies, and did:web resolves. did:ion, did:onion and did:webkey each return methodNotSupported.
  • @learncard/didkit-plugin vitest with this build's pkg/ files dropped into LearnCard main (dfefe5c71): 40/40, the same as the shipped WASM.
  • I didn't rerun the LearnCard service e2e for this version. The earlier run against the bigger cut set passed once its LinkErrors were traced to DEFAULT_DIDKIT_WASM_URL pointing at the shipped binary, and this build only puts code back.

To try it: wasm-pack build lib/web --target web --locked, then wasm-opt -Oz with the flags in lib/web/README.md, then drop the pkg/ files into LearnCard's packages/plugins/didkit/src/didkit/pkg/.

Not in here

  • JSON Schema and the big contexts. Dropped per review, see above. feat: opt-in features to trim the didkit WASM (LC-2429) ssi#17 adds the features those cuts used; this PR no longer needs it.
  • Pre-compressed brotli. I only looked into this, I didn't build it. Today learncard.app (Netlify) serves this file at 1.52 MB brotli and assets.learncard.ai (CloudFront) at 1.64 MB, while brotli-11 of the same bytes is 1.23 MB. CloudFront can serve a max-brotli file as-is if it's uploaded to S3 with Content-Encoding: br; Netlify would need an edge function or the app could load the WASM from the CloudFront URL.
  • Nightly immediate-abort. Probe measured another ~5% from this, but it pins a nightly toolchain in CI, so I left it out.

— Grok Bot

Two no-risk size cuts:

- codegen-units = 1 in the workspace release profile. LLVM sees the whole
  crate graph in one unit, so it inlines and dedupes more.
- didkit-wasm default features drop invoke and delegate. Those gate the 9
  zcap exports (delegateCapability, invokeCapability, verifyDelegation...),
  which LearnCard never calls. Build with --features invoke,delegate to
  get them back. The imports and helpers only those exports use are now
  gated too, so every feature combination still builds with -Dwarnings.
…uild (LC-2429)

The three methods become default features of the didkit crate, so the CLI,
HTTP server and C/Java bindings keep them. didkit-wasm already depends on
didkit with default-features = false, so it drops them.

None of them works in the browser today:
- did:ion reads DID_ION_API_URL from the environment, which a browser
  doesn't have, so every resolve fails with 'Missing Sidetree API endpoint'.
- did:onion sends plain HTTP to the .onion host with no Tor proxy.
- did:webkey has no callers in LearnCard and is the only reason the OpenPGP
  stack (pgp, dsa, sha1-checked) is linked in.

pgp was also the only crate turning on x25519-dalek's static_secrets
feature, which jwe.rs needs, so didkit-wasm now asks for it directly.
TAYLOR'S CALL. Turns on ssi-json-ld's omit-large-contexts for the WASM
build only. The static loader stops embedding https://schema.org/ (~200 KB)
and https://w3id.org/traceability/v1 (~123 KB).

What breaks: a document whose @context includes either IRI no longer
resolves from the built-in loader. It resolves if the caller puts the
context in the context map (LearnCard's getDocumentMap does this when its
context plugin can resolve the IRI, e.g. with remote contexts allowed);
otherwise expansion fails with 'Unknown context'. No LearnCard-issued
credential uses either context.

Needs learningeconomy/ssi 0c5405a (omit-large-contexts), so CI's SSI_REF
moves to it.
TAYLOR'S CALL. Turns on ssi-vc's omit-json-schema for the WASM build only.
boon and the regex engine behind it (~925 KB raw) stop being linked in.

What breaks: verifyCredential with checks: ['credentialSchema'] no longer
validates the credential against its 1EdTechJsonSchemaValidator2019
schema. It returns a warning ('credentialSchema not checked: ...') and
leaves credentialSchema out of checks. Proofs, status and expiry are
unaffected. LearnCard's vc plugin adds that check whenever a credential has
a credentialSchema (OBv3/CLR), so callers that need the check would have
to validate in JS (e.g. ajv) or on a server.

Needs learningeconomy/ssi 79b56b3 (omit-json-schema), so CI's SSI_REF
moves to it.
@TaylorBeeston
TaylorBeeston marked this pull request as ready for review November 17, 2026 00:44

@Custard7 Custard7 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the Rust/Cargo changes, SSI dependency, and current LearnCard consumers. CI is green, including WASM/JWE, native bindings and HTTP suites. I have not independently reproduced the reported bundle measurements or browser smoke tests.

The codegen/zcap and unused-resolver reductions look reasonable for the LearnCard profile, but I would not ship the schema-validation removal as the default yet. The inline finding is a behavior/acceptance regression, not merely a missing UI label.

For the other judgment call, I recommend retaining schema.org/traceability in the default profile for now, or making the reduced profile explicitly opt-in with a caller-side context migration and regression tests. Removing the static contexts breaks previously supported credentials unless callers supply the exact contexts. LearnCard defaults allowRemoteContexts to false, so there is no automatic network fallback. The additional ~35 KB compressed saving is small relative to that interoperability change. Please document the two capability changes in durable package/release documentation, not only this PR body.

Merge SSI first and revalidate the dependency ref (particularly if squash-merging). Keep any browser smoke test on matching generated JS and WASM artifacts; the unrelated published-binary results cannot validate this new profile.

Comment thread lib/web/Cargo.toml Resolved
Reverts 95f3369. omit-json-schema made verifyCredential return errors: []
for a signed, schema-invalid credential when the caller asked for the
credentialSchema check. Taylor's call is to keep the check.

This reverts commit 95f3369.
…-2429)

Reverts 9d6fc98. Taylor's call is to keep both contexts in the built-in
loader. With (c) and (d) gone, didkit-wasm no longer needs any ssi feature
from learningeconomy/ssi#17, so build.yml's SSI_REF goes back to main's.

This reverts commit 9d6fc98.
Reverts feb932d. It only moved push_image.yml to the ssi#17 head so it
matched build.yml. Nothing here needs that ref now, so both workflows go
back to 9e2783f, same as main.

This reverts commit feb932d.
Custard7 asked for the capability changes to live in the package docs, not
just the PR body. lib/web/README.md gets a section listing the dropped zcap
exports and the dropped did:webkey/did:onion/did:ion methods, and how to get
each back. The DID methods section from #21 now says those three return
methodNotSupported instead of describing their old browser failures.
CHANGELOG.md gets matching Unreleased entries.
@TaylorBeeston TaylorBeeston changed the title perf(wasm): shrink the WASM from 4.61 MB to 2.68 MB (LC-2429) perf(wasm): shrink the WASM from 4.61 MB to 3.93 MB (LC-2429) Nov 17, 2026

@Custard7 Custard7 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 5b64be4. The blocking schema-validation regression is addressed: lib/web/Cargo.toml no longer enables either SSI omission feature, and both workflows again pin SSI 9e2783f9f759fc92617f6c27b1c77ec0599cf9a0. JSON Schema validation and the built-in contexts are preserved. This PR no longer depends on ssi#17. The merged secp256k1 did:key feature remains enabled.

The remaining reductions and changed default exports/methods are documented in README/CHANGELOG. Current-head CI is green, including WASM library/JWE/did:key tests, WASM package build, native bindings/platform builds, and HTTP suites. No blocking findings remain. Source and hosted-CI review only; I did not independently reproduce the updated size measurements or Node smoke tests.

Nonblocking documentation nit: pulling in OpenPGP does not itself demonstrate that did:webkey could not work in a browser. Describe that removal as unused by LearnCard / a size tradeoff, rather than categorically browser-inoperable. The explicit methodNotSupported behavior is correctly documented.

@TaylorBeeston
TaylorBeeston merged commit 9dc2270 into main Nov 17, 2026
7 checks passed
@TaylorBeeston
TaylorBeeston deleted the perf/lc-2429-wasm-size branch November 17, 2026 20:02

TaylorBeeston commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

Acceptance Loom for LC-2429 (prod learncard.app, demo):
https://www.loom.com/share/3a3fc8ceb1dc4a16a453248af9028e88

On camera: Network filter wasm → didkit_wasm_bg-NANe9H4w.wasm Size 1,288 kB (200). Independent measure: raw 3,935,119 (~3.93 MB) / Netlify br 1,286,966 (~1.29 MB). Matches this PR’s shrink.

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