Skip to content

Run analysis simulations in webworkers#1105

Open
jmoggr wants to merge 7 commits intomainfrom
simulation-webworkers
Open

Run analysis simulations in webworkers#1105
jmoggr wants to merge 7 commits intomainfrom
simulation-webworkers

Conversation

@jmoggr
Copy link
Collaborator

@jmoggr jmoggr commented Mar 9, 2026

No description provided.

@jmoggr jmoggr added enhancement New feature or request frontend TypeScript frontend and Rust-wasm integrations labels Mar 9, 2026
@jmoggr jmoggr marked this pull request as ready for review March 9, 2026 17:23
@jmoggr jmoggr requested a review from kasbah as a code owner March 9, 2026 17:23
@kasbah
Copy link
Member

kasbah commented Mar 10, 2026

Is there any indication that this is faster than the non web-worker execution?

@jmoggr
Copy link
Collaborator Author

jmoggr commented Mar 10, 2026

Faster at running the simulations? Probably not. I didn't measure, but I didn't notice a meaningful difference. If anything I would expect the simulations to be slightly slower given IO and some amount of duplicated work. The webworker can't run the blocking simulation any faster than the main browser thread.

Faster at producing a responsive page? Yes. Before analysis page I was testing with froze for ~5s after loading until all the simulations were completed, now the page becomes responsive immediately. I think we still spending ~100ms to kick all this off from the main thread, but I think that's acceptable.

Unfortunately the analysis Tim shared with me for testing is not public: http://localhost:5173/analysis/019cafd4-19fb-7b62-9e11-ceda2da5da67


There is another major benefit beyond speed: This also allows you to change parameters while the simulation is running, cancelling the previous run. Before it was relatively easy to cause a simulation to permanently freeze a page (exponential O(n) in the simulation).

Copy link
Member

@kasbah kasbah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does indeed improve loading Tim's big model ™ . Suggestions and questions below.

@epatters epatters added the performance Making things go fast label Mar 10, 2026
@epatters
Copy link
Member

epatters commented Mar 10, 2026

Is there any indication that this is faster than the non web-worker execution?

Right, to build on Jason's response, this isn't about making the simulations faster per se but making the rest of the application be more responsive while simulations run.

If you really want to stress test this feature, try to doing a loop finding analysis into a large causal loop diagram, with a high upper limit on the lengths of the paths considered. Because the homomorphism finding has combinatorial complexity, this blows up quickly. In fact, I had to make the fix #419 a while back because the whole browser would freeze if you didn't impose a limit on the path length.

jmoggr added 5 commits March 16, 2026 10:55
# Conflicts:
#	packages/frontend/src/stdlib/analyses.tsx
#	packages/frontend/src/stdlib/analyses/mass_action.tsx
#	packages/frontend/src/stdlib/analyses/simulator_types.ts
#	packages/frontend/src/stdlib/theories/petri-net.ts
#	packages/frontend/src/stdlib/theories/primitive-signed-stock-flow.ts
#	packages/frontend/src/stdlib/theories/primitive-stock-flow.ts
@jmoggr jmoggr force-pushed the simulation-webworkers branch from 1413fc1 to 74a9320 Compare March 16, 2026 15:32
@kasbah kasbah requested a review from epatters March 18, 2026 12:20
@kasbah
Copy link
Member

kasbah commented Mar 18, 2026

Needs a rebase/merge and would be good to get @epatters eyes on this too.

@epatters
Copy link
Member

Yep, I'm planning to review this one too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request frontend TypeScript frontend and Rust-wasm integrations performance Making things go fast

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants