Skip to content

JSPI scheduler #4789

Open
Open
@pulsejet

Description

@pulsejet

(This may end up being more of a thought experiment, please feel free to close this issue)

JSPI is supposed to be the spiritual successor to asyncify, which tinygo currently uses for scheduling on GOOS=JS. At a high level (from my understanding) JSPI essentially provides some form of constrained stack switching (e.g. cannot suspend JS frames).

Out of curiosity and with my (very) limited knowledge of how tinygo or JSPI works, I took a shot at this and got some a basic Go program with goroutines to work without asyncify on Chrome. In my implementation,

  1. Each goroutine is a separate stack
  2. Pause suspends the stack and puts the promise in a global map
  3. Resume suspends the current stack and resolves the promise, reverting back to the old goroutine
  4. After suspending the stack, the scheduler is invoked directly. If there is no more work, a trap gets rid of the stack.

If anyone is curious - here's where I stopped
pulsejet@28c1d8d

I think (with my limited knowledge) it's hard to say which approach is faster (unwind-rewind, or a JS call for each scheduler event), so it might make sense to run some benchmarks first.

As the first line says, please close if this is a stupid idea.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestwasmWebAssembly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions