Repository navigation
Add an experimental WebAssembly Dedither with identical output (#68) - #245
Merged
Merged
Conversation
Port the dedither kernel to Rust in a separate wasm/ crate, built with plain cargo and wasm-bindgen-cli (npm run build:wasm, part of npm run build unless KROMACUT_SKIP_WASM=1). Its output matches the JavaScript kernel byte for byte. A new experimental switch in Settings, off by default, makes the dedither worker try WebAssembly first; it falls back to JavaScript if the kernels are missing or fail to load or run. CI builds the kernels with a pinned toolchain. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… download - build-wasm.mjs reads the wasm-bindgen version from a CRLF Cargo.lock, as Windows checkouts have it, and passes an explicit --target-dir so a CARGO_TARGET_DIR override cannot package a stale kernel. - CI builds the kernels on Windows, macOS and Linux in rust_tests, as release does. Release, Pages and that job build without the shared cache, which the ubuntu-24.04 checks job saves. - The loader gives up on a .wasm download after 10 s, so a stalled fetch falls back to JavaScript instead of holding the edit open. - Vite's dev watcher ignores wasm/target. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
vycdev
force-pushed
the
t3/wasm-dedither
branch
from
November 30, 2026 10:45
b1363ce to
c84a89d
Compare
vycdev
added a commit
that referenced
this pull request
Nov 30, 2026
- Treat the stored-session read as pending until it answers, so a read slower than startup's 4 s wait never shows the drop zone over an image about to be restored (smoke test holds the read past startup). - Try a sample waits for a file that is still being checked. - Move focus to Choose image after Remove image, and to Choose file after Try a sample, instead of losing it to the page. - Only file drags light up the drop zone, and moving over the card's children keeps the highlight. - Keep the card reachable and its buttons wrapping in short or narrow panes. - Docs: qualify recovery, say what happens to the sample and that Remove image shows the drop zone, in all 12 languages; zh-CN/ja spacing. - Load the sample in the WebAssembly dedither specs from #245. Co-Authored-By: Claude Opus 5.5 <[email protected]>
vycdev
added a commit
that referenced
this pull request
Nov 30, 2026
- Treat the stored-session read as pending until it answers, so a read slower than startup's 4 s wait never shows the drop zone over an image about to be restored (smoke test holds the read past startup). - Try a sample waits for a file that is still being checked. - Move focus to Choose image after Remove image, and to Choose file after Try a sample, instead of losing it to the page. - Only file drags light up the drop zone, and moving over the card's children keeps the highlight. - Keep the card reachable and its buttons wrapping in short or narrow panes. - Docs: qualify recovery, say what happens to the sample and that Remove image shows the drop zone, in all 12 languages; zh-CN/ja spacing. - Load the sample in the WebAssembly dedither specs from #245. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Step 1 of the WebAssembly pilot in #68. Dedither is the first kernel to get a Rust/WebAssembly version, behind an experimental switch. #242 already made the JavaScript version deterministic and moved it to a worker, so the WebAssembly output can be checked byte for byte against the same goldens.
What changes for users: a new WebAssembly acceleration switch under Experimental in Settings, off by default. When it is on, Dedither runs the Rust kernel. The output is identical, so the switch never changes results. If the WebAssembly file can't load or run, Dedither uses JavaScript, still finishes, and logs one console warning. Nothing else changes.
How it's built
wasm/is a separate cargo workspace, not shared withsrc-tauri.kromacut-wasm/src/dedither.rsis a plain-Rust port ofsrc/lib/dedither.ts(same scan order, tie hash, and in-place two-row algorithm), with nativecargo tests.lib.rsis only the wasm-bindgen wrapper (wasm-bindgen = "=0.2.130").scripts/build-wasm.mjs(npm run build:wasm) runs plaincargo build --release --target wasm32-unknown-unknownandwasm-bindgen --target webintosrc/wasm/pkg/, which is gitignored. No wasm-pack. It refuses awasm-bindgen-cliwhose version differs from the crate's inwasm/Cargo.lock.npm run buildnow runs it and fails without the toolchain, unlessKROMACUT_SKIP_WASM=1is set. That produces a JS-only build: the loader finds no kernels and the worker uses JavaScript.npm run devworks either way.src/lib/deditherJob.ts, with the WebAssembly run adapter insrc/lib/deditherWasm.ts..wasmfile is fetched lazily..github/actions/setup-wasm, installs Rust 1.100.0 withwasm32-unknown-unknown,wasm-bindgen-cli0.2.130 (taiki-e/install-action), and a shared cargo cache that only the ubuntu-24.04checksande2ejobs use.deploy-pagesandreleaseuse the action withcache: 'false', building from scratch as they did before. Inreleaseit runs before Rust stable, so the desktop app keeps building on stable. The build script runscargo +$KROMACUT_WASM_TOOLCHAIN --target-dir wasm/target, so the pin applies only to the WebAssembly build.checksalso runs the crate's native tests. Therust_testsmatrix (Windows, macOS, Linux) now builds the kernels too, so a release-only platform breakage shows up on PRs.Before → after
All runs used production builds in headless Chromium 148 on an Apple M6. Times go from the Dedither Apply click until the result is committed; each value is the median of 5 runs.
develop(JS)WebKit 26.4 (Playwright), median of 3, switch off → on:
The dedither step alone, in Node/V8: a fresh instance each time, including compile, instantiate and both copies.
That's about 2×. End to end the gain is smaller, because image decoding and PNG encoding are shared by both versions.
Bundle size
developkromacut_wasm_bg.wasm(fetched only when the switch is on and a dedither runs)dedither.worker.jsindex-*.jschunksVerification
tests/deditherWasm.test.ts:>=to>in the Rust keep rule makes 3 of these tests fail.src/wasm/pkgisn't built, and fails underCI.cargo test(6 tests),cargo clippy -D warningsandcargo fmt --checkare clean inwasm/.tests/e2e/dedither.spec.ts: a@smoketest turns the switch on in Settings and checks that the.wasmis requested only once a dedither runs and that the output is the golden with no fallback warning. Another serves the.wasmas a 404 and checks the golden output and a warning naming the 404. A third never answers the.wasmrequest: the loader gives up after 10 s and the job finishes in JavaScript with the golden output. That test fails if the deadline is removed.npm run lint,npx tsc -b,check:i18nandtest:docs.npm test: 1286 passed, 1 pre-existing skip.npm run test:e2e:allon port 47391 at 29daabc: all 8 suites passed (263 tests), with no port reported as already in use. The last commit only tightens one assertion indedither.spec.ts, which passes (5/5).landing.spec.tsnow expects Shift+Tab from Close to wrap to the new switch, which is the dialog's last control.cargo test --lockedinsrc-tauripasses (42 tests), andnpx tauri build --no-bundlebuilds the release desktop binary with the.wasmembedded.KROMACUT_SKIP_WASM=1 npm run buildsucceeds with no.wasmindist. Withoutwasm-bindgen-cli,npm run build:wasmfails with an install hint.Untested
'wasm-unsafe-eval', and the build embeds the.wasm.release.ymlanddeploy-pages.ymlonly run on release, so they haven't run. Every step they use does run on this PR: the same composite action, the same build script on Windows, macOS and Linux (rust_tests), andnpm run build(checks).Council review
Rounds: 2. Gemini was unavailable (every Gemini-capable provider is disabled here), so the council had two members.
Round 2 verdict: both approve.
Fixed in round 1:
build-wasm.mjscould not read the wasm-bindgen version from a CRLFCargo.lock, as Windows checkouts have it. Both Windows release builds would have failed (blocker).--target-diris now explicit, so aCARGO_TARGET_DIRoverride can't package a stale binary.rust_testsno longer restore the ubuntu-24.04 cache onto other images..wasmdownload now times out after 10 s and falls back to JavaScript instead of holding the edit open.wasm/target.Declined, as follow-ups:
MAX_U32clamps are harmless.route.fulfillcan't hold a body open, and Sol verified both stall paths reject in Chromium.Created with Claude Opus 5.5 in Claude Code; council reviews by Claude Opus 5.5 and GPT-6.2 Sol.
🤖 Generated with Claude Code