Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for parallelism in the runtimes. #184

Open
Idorobots opened this issue Jan 1, 2024 · 0 comments
Open

Support for parallelism in the runtimes. #184

Idorobots opened this issue Jan 1, 2024 · 0 comments

Comments

@Idorobots
Copy link
Owner

Currently, the runtimes support* concurrency by spawning green threads, but it would be really nice to actually run these in parallel. Racket supports places, but that requires serialization of the spawned closure. Similarly, Node.js and the browsers support Workers that, again communicate via message passing and require some form of serialization of the closure that is to be spawned in a given worker.

Right now, it's not possible to serialize functions to pass them along to the worker/place, but it should be possible to pass an offset into a function table. This function table can be created after hoisting the functions into the global scope and stored at the module level. Then, assuming that all the places/workers load the relevant modules, it should be possible to serialize a closure by just serializing each item in its environment and the function offset into the module table:

(define __foo (lambda (env x c) ...))
(define __bar (lambda (env y c) ...))

...
(&make-closure (&make-env (&make-closure (&make-env 23) __foo)) __bar)

;; Becomes:

(define __functions
  (vector (lambda (env x c) ...) ;; __foo
          (lambda (env y c) ...))) ;; __bar
...

(&make-closure (&make-env (&make-closure (&make-env 23) 0)) 1)

This representation can be then passed to a separate place/worker and reconstructed for execution. Alternatively, the offset can be used directly on each &apply call to facilitate hot code reloading.

As a bonus, given this scheme a place/worker doesn't have to run on the same machine anymore, as all values become serializable and can be sent over the wire. Assuming both sides are running compatible module code.

  • Not quite true for JS just yet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant