Repository navigation
perf(wasm): run functions without Asyncify when no import can suspend - #1087
Merged
Merged
Conversation
Every WASM function was compiled with the Asyncify transform as soon as one registered host function was async, for example the blocking output-stream flush that Rust std calls on its print and panic paths. Stdio streams never suspend, so a function that imports only wasi:io, wasi:cli, wasi:clocks and wasi:random paid for instrumentation it can never use: about 1.5x slower calls and seconds of transform work on the first load of a large module. Host profiles now declare NeverSuspends, and the function manager compiles a module synchronously when none of its imports can suspend. Imports that can suspend (poll, filesystem, sockets, http, actor, funcs, unknown) keep the transform.
skhaz
added a commit
to kicksideai/converters
that referenced
this pull request
Nov 15, 2026
Rendering and encoding use WebAssembly SIMD: 1.30-1.45x faster per page, with the same memory and allocations. BREAKING CHANGE: the component needs a Wippy runtime whose Asyncify transform supports SIMD (wippyai/wasm-runtime#22) and that runs functions without Asyncify when no import can suspend (wippyai/runtime#1087). Earlier runtimes fail to load it.
- wasm-runtime validates each signature TypeDef once per module instead of on every call: 266 -> 45 Go allocations per pdf2image page render together with the wazero change below. - wazero watches call contexts with context.AfterFunc and a reused watch instead of a goroutine per call, and doubles linear memory capacity on growth instead of reallocating the whole memory about every 1.25x.
… into review-1087
… into review-1087
wolfy-j
approved these changes
Nov 15, 2026
wolfy-j
left a comment
Contributor
There was a problem hiding this comment.
Reviewed the synchronous WASM selection and final dependency composition. Restricted the shortcut to isolated runtimes; a red/green regression proves shared runtimes retain async imports registered by siblings. Pins merged wasm-runtime #22 and wazero #2, including SIMD suspend/rewind coverage and the repaired cancellation-watch lifetime. Runtime WASM and boot WASM suites pass under the race detector against these production changes; scoped vet passes. Final CI must be green before merge.
skhaz
added a commit
to kicksideai/converters
that referenced
this pull request
Nov 15, 2026
…need - page_resources counts the images each page paints without decoding them (unpdf ParseOptions::with_resource_counts). - unpdf keeps simple ToUnicode bfrange entries as ranges. An identity CMap over the BMP, as html2pdf writes, was 65,536 strings per font. - unpdf keeps image metadata on the page without a second copy of the image bytes. - Pages that paint the same PDF object encode the image file once. - Encoded image streams move into the output instead of being copied, and 8-bit gray/RGB samples go to the PNG encoder without a copy. - PNG uses zlib level 2 with the Up filter instead of level 6. - Build the component with SIMD128. BREAKING CHANGE: the component needs a Wippy runtime whose Asyncify transform supports SIMD (wippyai/wasm-runtime#22) and that runs functions without Asyncify when no import can suspend (wippyai/runtime#1087). Earlier runtimes fail to load it.
skhaz
added a commit
to kicksideai/converters
that referenced
this pull request
Nov 15, 2026
7148e3f removed SIMD128 so the component loads on released runtimes, and 17309bf replaced the document cache with a parse per request. Both are restored, keeping the request bounds, the JPEG chroma fidelity test and full-resolution chroma from 17309bf: - SIMD128 renders and encodes 1.30-1.37x faster per page and per batch (8-page JPEG batch 262 -> 191 ms, 8-page PNG 317 -> 244 ms). - The cache keeps only the last document of each pool instance, so the per-page and per-group calls of one document parse it and load its fonts once. Tests now check that repeated, failed and different requests never retain more than one document. Add the SPDX headers the legal check requires on the files 17309bf added. BREAKING CHANGE: the component needs a Wippy runtime whose Asyncify transform supports SIMD (wippyai/wasm-runtime#22) and that runs functions without Asyncify when no import can suspend (wippyai/runtime#1087). Earlier runtimes fail to load it.
skhaz
added a commit
to kicksideai/converters
that referenced
this pull request
Nov 15, 2026
c287682 removed SIMD128 so the converters load on released runtimes. SIMD is restored to keep the faster builds; the -O3 html2pdf build and the wippy/test lock update from c287682 stay. BREAKING CHANGE: the components need a Wippy runtime whose Asyncify transform supports SIMD (wippyai/wasm-runtime#22) and that runs functions without Asyncify when no import can suspend (wippyai/runtime#1087). Earlier runtimes fail to load them.
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.
Reason for This PR
WASM functions that can never suspend still ran with Asyncify instrumentation. For the PDF rasterizer component this made each call about 1.5x slower, and the first load of the module cost about 5 s of transform work.
Description of Changes
Speedup
kickside/pdf2image, same module): 1.5x faster (PNG 790 → 525 ms, JPEG 356 → 254 ms, WEBP 270 → 192 ms).kickside/doc2md: 1.35-1.9x faster (convert 105 → 71 ms, page_resources 55 → 28 ms).Every WASM function was compiled with the Asyncify transform as soon as one registered host function was async. One example is
output-stream.blocking-flush, which Rust std calls on its print and panic paths. Stdio streams never suspend:blockingOutput/blockingInputsuspend only for buffered streams, which come from sockets, HTTP bodies and files. So a function that imports onlywasi:io,wasi:cli,wasi:clocksandwasi:randompaid for instrumentation it can never use.HostProfile.NeverSuspendsmarkswasi:io,wasi:cli,wasi:clocksandwasi:random.HostRegistry.MaySuspend(imports)is true when any import can suspend or is unknown.go.modupdates wasm-runtime (synchronous compile, SIMD Asyncify fix, schema validation once per type) and the wazero fork (context watch without a goroutine per call, geometric memory growth).CompileConfig{Synchronous: true}whenMaySuspendis false. Shared runtimes keep normal Asyncify derivation because sibling entries may have registered additional hosts. Such an instance has no Asyncify scheduler, soProcesstakes the existing synchronous step path.This needs wippyai/wasm-runtime#22 and wippyai/wazero#2.
go.modpoints at their branch heads. I will update it to the merge commits after those PRs merge.Measurements
The measurements use
kickside/pdf2image(Rust component, importswasi:io,wasi:cli,wasi:random), one A4 page at 150 DPI, Apple M-series,wippy testwith the same module and the same SDK.kickside/doc2mdconvert, 2 test PDFskickside/doc2mdpage_resourceskickside/html2pdfimportswasi:filesystem, so it keeps the transform and has no change (34 ms).Tests
TestHostRegistryMaySuspend.go test ./runtime/wasm/... ./boot/components/runtime/wasm/...passes.wippy teston thepdf2image(99 tests),html2pdf(33 tests) anddoc2mdsuites: all pass.Review corrections
Dependency follow-up
The wazero update replaces per-call watcher goroutines with a reusable context.AfterFunc watch and doubles linear-memory backing capacity on growth, capped by the declared maximum. Review fixed nested background calls disabling the outer cancellation watch and serialized callback closure with watch reuse. Spare backing capacity can increase compared with Go’s append growth; guest-visible memory and admission limits are unchanged.
Validation includes the runtime WASM and boot WASM suites with the race detector against these exact production changes; all passed.