quantified-uncertainty / squiggle

An estimation language
https://squiggle-language.com
MIT License
152 stars 23 forks source link

Async evaluation #1071

Closed berekuk closed 1 year ago

berekuk commented 2 years ago

It'd be nice if Project.run had an async interface. Right now evaluations freeze the entire JS thread.

There are problems with this (wrapping stuff in promises and passing continuations around is not easy) and we might solve the same issue with web workers. But I'm filing this here for future reference and discussions.

umuro commented 2 years ago

I think we have to go for web workers and shared memory. And we should not bother to support environments where shared memory is not available.

berekuk commented 2 years ago

I still think we need all of:

berekuk commented 1 year ago

I tried to implement async squiggle code evaluation.

It's not hard technically, but the performance turned out to be prohibitive; it's 20x slower than the sync version for the basic List.upTo(1, n) -> map({|x| x}) benchmark.

There's some potential for optimizations (for example, not all function registry definitions have to be async, only those that take lambdas as a parameter), but I don't expect it to help enough for async to be viable.

Also, supporting both sync and async version would be a pain, we'd have to keep duplicate copy-pasted versions for half of our codebase.

berekuk commented 1 year ago

I don't think this is possible anymore. We should start using Web Workers instead.