Repository navigation
perf(wasm): shrink the WASM from 4.61 MB to 3.93 MB (LC-2429) - #22
Conversation
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.
Custard7
left a comment
There was a problem hiding this comment.
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.
…-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.
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.
Custard7
left a comment
There was a problem hiding this comment.
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.
|
Acceptance Loom for LC-2429 (prod On camera: Network filter |
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 thecredentialSchemacheck, so Taylor decided to keep both.df41b05and32a36abrevert those two cuts, ande79fb2ereverts the matchingSSI_REFbump inpush_image.yml. Both workflows are back on main's ssi ref (9e2783f), so this PR doesn't depend on learningeconomy/ssi#17 anymore.35d08895b64be4Both come from wasm-pack 0.13.1 plus
wasm-opt -Ozfrom 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 on82ef1d9: (a) −193,287 raw / −43,302 brotli, (b) −482,258 / −127,840.What changed
(a)
d325438:codegen-units = 1in the workspace release profile, and didkit-wasm's default features dropinvokeanddelegate. 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,delegateto get the zcap exports back. I also gated the imports and helpers that only those exports use, so the default set,invoke,delegate,zcapandinvokeeach build cleanly with-Dwarnings. One side effect:codegen-units = 1applies 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 thedidkitcrate. The CLI, HTTP server and C/Java bindings keep all three. didkit-wasm already usesdefault-features = false, so it drops them. None of them works in a browser today:Missing Sidetree API endpoint..onionhost.With this cut, all three return
methodNotSupportedin the WASM. pgp was also the only crate turning on x25519-dalek'sstatic_secrets, whichjwe.rsneeds, so didkit-wasm now asks for that feature directly.Docs (
5b64be4):lib/web/README.mdhas 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 returnmethodNotSupported.CHANGELOG.mdgets matching Unreleased entries, including the newdid-webkey/did-onion/did-ionfeatures for anyone depending ondidkitwithdefault-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 --libpasses (4 tests, including fix(wasm): secp256k1 did:key in the WASM build (LC-2431) #21's secp256k1 round trip).methodNotSupported.@learncard/didkit-pluginvitest with this build'spkg/files dropped into LearnCard main (dfefe5c71): 40/40, the same as the shipped WASM.LinkErrors were traced toDEFAULT_DIDKIT_WASM_URLpointing at the shipped binary, and this build only puts code back.To try it:
wasm-pack build lib/web --target web --locked, thenwasm-opt -Ozwith the flags inlib/web/README.md, then drop thepkg/files into LearnCard'spackages/plugins/didkit/src/didkit/pkg/.Not in here
Content-Encoding: br; Netlify would need an edge function or the app could load the WASM from the CloudFront URL.— Grok Bot