feat(bench): add WASM benchmark harness and native allocation profiler#3153
Open
k4sperski wants to merge 13 commits intoAutomattic:masterfrom
Open
feat(bench): add WASM benchmark harness and native allocation profiler#3153k4sperski wants to merge 13 commits intoAutomattic:masterfrom
k4sperski wants to merge 13 commits intoAutomattic:masterfrom
Conversation
Contributor
Author
|
Moving to draft, needs a bit more refinement! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issues
Follows up on #3025.
Description
Adds benchmarking infrastructure to measure spell-check performance in WASM and track allocation overhead; two dimensions native Criterion benchmarks don't cover.
fuzzy_matchis cheap on modern machines, but on lower-end devices WASM is slower and allocation costlier; these tools make that overhead visible.Validated against #3025 (
is_already_lower):WASM time reductions track #3025's native Criterion numbers, so the optimisation carries through the WASM pipeline. Capitalised is flat because
is_already_lowerdoesn't trigger on uppercase starts.What's added
harper-core/examples/alloc_profile.rs): counts allocs per word infuzzy_matchvia a#[global_allocator]. No extra deps. Run withjust alloc-profile.harper-wasm/src/bench.rs): feature-gatedPreparedWordsstruct exposingfuzzy_matchto JS. Constructor parses the word list and caches anArc<FstDictionary>; the method just runs the spell-check loop.cfg(feature = "bench")keeps it out of production builds.harper-wasm/benches/wasm_bench.js): Node script timingfuzzy_matchunder WASM to verify native perf wins carry through. Run withjust bench-wasm.Measurement hygiene
PreparedWordsparses inputs and caches the dictionary once, outsidebench(), so the timed region only containsfuzzy_matchwork, matching the native criterion pattern.AUTOMATON_BUILDERSthread_local before measuring, so the first case doesn't absorb its one-time lazy-init cost.just bench-wasmbuilds intopkg-bench/, so the shippingpkg/stays untouchedWASM Time: baseline vs optimised
xychart-beta title "WASM fuzzy_match: ms/iter min (lower is better)" x-axis ["mixed", "lowercase", "capitalized"] y-axis "ms/iter" 0 --> 100 bar [96, 84, 80] bar [54, 43, 80]Methodology
Trade-offs
just bench-wasmbefore merging perf-sensitive changes. CI integration would be the natural next step if this becomes a recurring gap.bench-wasmwith the defaultwasm-optbuild adds ~30s per rebuild.DISABLE_WASM_OPT=1 just bench-wasmskips it for faster dev iteration; the numbers that ship in this PR were measured withwasm-opton.Follow-ups
MAX_EDIT_DISTANCE/MAX_RESULTSas args sojust bench-wasmbecomes the single source of truth for the duplicated constants.PreparedWordsto coversuggest_correct_spellingand merged-dict lookup when optimisation work warrants it.Demo
N/a
How Has This Been Tested?
cargo build -p harper-wasm: production build unaffected (nobenchfeature).cargo clippy -p harper-wasm --features bench -- -Dwarnings: clean.just alloc-profile: first case no longer inflated by thread-local init.just bench-wasm: runs end-to-end;PreparedWords.free()called so no wasm-bindgen leaks.Checklist