News for hackers. Stuff that matters.
Re:Show HN: Scratch.js – Interactive JavaScript Scratchpad by emmanueloga_ on Wednesday November 18, 2020 @02:27PM (#25141238)
Re:Show HN: Scratch.js – Interactive JavaScript Scratchpad by rng_civ on Wednesday November 18, 2020 @02:40PM (#25141412)
To add to this comment, Stopify is a JS-to-JS compiler that instruments sync JS code to make them interruptible at set points. The paper [0] can explain it better than I ever could.

I work on an experimental Pyret [1] runtime that uses Stopify to instrument compiled Pyret code (plain old JS) so that we can run Pyret code on the main page thread without hanging it up. Main thread execution is important for quick/easy DOM access. In terms of performance cost, we haven't measured too extensively, but so far, on average, we're seeing a 2x slow down compared to un-Stopified programs.

(Disclaimer: paid contributor for Pyret).

[0] https://www.stopify.org/research.html

[1] https://www.pyret.org/

Re:Show HN: Scratch.js – Interactive JavaScript Scratchpad by angleofrepose on Wednesday November 18, 2020 @05:16PM (#25143214)
Do you see any other solutions in the same domain as Stopify? Another method that might provide a way to keep UI unblocked but still have user executable code?
Re:Show HN: Scratch.js – Interactive JavaScript Scratchpad by rng_civ on Wednesday November 18, 2020 @06:18PM (#25143969)
If you need the user code to execute on the main thread, then unfortunately I am aware of none besides bundling your own tailored system.

Pyret used to use its own runtime system [0] but Stopify was created in part to replace it due to the maintenance burden and complexity of "vanilla" JS interoperability.

[0] https://www.pyret.org/docs/latest/s_running.html

Re:Show HN: Scratch.js – Interactive JavaScript Scratchpad by angleofrepose on Wednesday November 18, 2020 @02:44PM (#25141479)
This is what I use. Seems to be the only option, and it works.