Repository navigation
Core: speed up WASM validation exports and add benchmarks - #7
Open
Fellmonkey wants to merge 2 commits into
Open
Fellmonkey wants to merge 2 commits into
Fellmonkey wants to merge 2 commits into
Conversation
- move WASM export logic into a js-free API so it is testable natively - memoize goValidate/goParseDomain results and goSpecmeta JSON - cut identifier and modifier-split allocations in the hot parse path - add native benchmarks, a Node WASM smoke harness and measured results Benchstat, Windows/amd64 Ryzen 7 5800X, Go 1.27.4, -count=6+8, base main@8927417 vs PR after re-sync: Specmeta 22.7us -> 3.4ns -100% StudioValidationCycle/same-yaml 2.66ms -> 2.0us -99.9% StudioValidationCycle/changing 2.59ms -> 2.27ms -12.5% SplitIdentifier/simple 192ns -> 16ns -92% ToDatabaseColumnName/simple 183ns -> 5.7ns -97% Validate/entities=2000 18.4ms -> 13.8ms -25% Node, 200 calls, median of 4 interleaved runs, ms/call: goValidate (same) 0.26 -> 0.055 goParseDomain (same) 0.19 -> 0.021 goSpecmeta 0.14 -> 0.016 studio cycle 0.39 -> 0.042 Cold per-call paths are unchanged within noise.
Fellmonkey
force-pushed
the
perf/wasm-benchmarks
branch
from
November 26, 2026 19:53
13ca152 to
40aa887
Compare
- expose goGenerate(yaml, bridge, packagesJSON) returning generated files - load the embedded bridges tree through a new fs.FS renderer path - keep CLI rendering byte-identical (TestRenderMemoryMatchesDisk) - stub package resolution and bridge clone/update code for js/wasm The naive build grew from 5.9 MB to 19.4 MB; the WASM-only stubs bring it back to 10.2 MB raw (2.6 MB gzip). RenderMemory adds no disk or symlink machinery, so browser generation stays bounded by the returned JSON. go test ./... -count=1 and make lint pass; Node smoke generates 6 files for admin-alpine in ~9 ms.
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.
What this changes and why
No issue: this is the WASM performance and browser-generation task requested directly.
Performance. All five existing WASM exports (
goValidate,goParseField,goParseDomain,goSpecmeta,goVersion) now have native benchmarks and a Node smoke harness. The export logic lives in a js-freeapi.go, so the browser path is the one being measured.Browser generation. A sixth export,
goGenerate(yaml, bridge, packagesJSON), builds the IR, resolves theextendschain from the embeddedbridges/tree and returns generated files as JSON. Disk rendering is unchanged:TestRenderMemoryMatchesDiskproves byte-identical output.Changes:
goValidate/goParseDomainresult and thegoSpecmetaJSON;SplitIdentifier,PascalCase,ToDatabaseColumnNameandSplitRespectingQuotesa fast path for the common case;Validationsonly when a field actually has a validation modifier;renderer.NewFromFS+RenderMemory, with js/wasm stubs that keep the network-backed package resolver and bridge clone/update code out of the browser binary;main.How you tested it
Benchstat, base
main@8927417vs this branch, Windows/amd64 Ryzen 7 5800X, Go 1.27.4:SpecmetaStudioValidationCycle/same-yamlStudioValidationCycle/changing-yamlSplitIdentifier/simpleToDatabaseColumnName/simpleValidate/entities=2000ParseField/modifiersGenerateYAMLReal WASM, Node 24, 200 calls, median of four interleaved runs, ms/call:
goValidate(same YAML)goValidate(new YAML)goParseDomain(same YAML)goParseDomain(new YAML)goSpecmetagoParseFieldgoGenerate(admin-alpine)Cold per-call paths are unchanged within noise. An earlier attempt to cache
*parser.RawSchemawas dropped: it raised GC pressure and slowed every other WASM export; only strings are cached now.Binary size. The naive renderer wiring grew the WASM file from 5.90 MB to 19.38 MB. WASM-only stubs for package resolution and bridge resolution bring it to 10.24 MB raw / 2.64 MB gzip (base: 5.90 MB raw / 1.61 MB gzip).
-ldflags "-s -w"produces 10.01 MB. NuGet versions are not resolved in the browser; callers pass them viapackagesJSON. Disk writes,--pruneand--migratestay outside the browser.Tested on: local Windows, Go 1.27.4, Node 24.18.1; CI-equivalent
make lintandgo test ./....How you found it
AI tools used to write this change: yes. OpenCode (
hy4-flash-free) wrote the native benchmark harness, the js-free API extraction, the Node smoke harness, the in-memory renderer path, the identifier fast paths and the measurements; it used pprof, benchstat and binary-size probes to choose the changes. The human author reviewed every file and the final numbers before opening and updating this PR.Checklist
make fmt,make lintandmake testpasscompliance-suite/regressions.tsv