WebAssembly module: all problem types, sessions and a Web Worker - #633
Merged
Merged
Conversation
This was referenced Oct 3, 2026
- The module solves every problem type: rectangleguillotine, rectangle, box, boxstacks, onedimensional and irregular. - 'Session' solves an instance without blocking: 'start' runs the optimization in a thread of its own, 'poll' returns the updates (each time the best solution or a bound improves) since the previous call and, at the end, the result, and 'stop' stops the optimization. The updates are queued by the threads of the algorithms, which can't call the JavaScript functions of the thread owning the session. - 'wasm/js/packingsolver_worker.js' runs sessions in a Web Worker and posts the updates and the result to the page; it also runs in Node with 'worker_threads'.
fontanf
force-pushed
the
wasm-all-types-worker
branch
from
October 3, 2026 19:17
31eed86 to
81983ec
Compare
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.
Stacked on #632: this PR's diff only shows the second step. Once #632 is merged, GitHub retargets it to
master.Changes
All problem types:
solveandSessionacceptrectangleguillotine,rectangle,box,boxstacks,onedimensionalandirregular, through one generic template over the six namespaces.Session: solving without blocking.startruns the optimization in a thread of its own and returns immediately.pollreturns the updates since the previous call. There's an update each time the best solution or a bound improves, so an update may have no new solution, e.g. the bound found before any solution. At the end,pollalso returns the result.stopstops the optimization. Withtimer.add_end_boolean, as in the Python bindings.poll. The calling thread never blocks.Web Worker:
wasm/js/packingsolver_worker.jsruns a session and posts the updates to the page.{type: "solve", problemType, instance, parameters},{type: "stop"}{type: "ready"},{type: "solution", output, certificate},{type: "done", output, certificate},{type: "error", error}It's a classic worker in the browser. It also runs in Node with
worker_threads, which is how it's tested.Size: with the six types, the module is 7.4 MB, 2.4 MB gzipped.
Testing
node --test wasm/tests/: 31 tests, all passing in three consecutive runs. None uses a time limit.solve, each problem type innot-anytimeandnot-anytime-sequentialmodes. Also the rectangle tests of Add a WebAssembly module #632: anytime mode on an instance proven optimal, the README example in the three non-anytime modes, and the error cases.Session:Not tested in a browser yet: that needs a page served with the headers enabling
SharedArrayBuffer, the next step.