Better HN
topnewbestaskshowjobs
Log inSign up

W4G1

68 karma · joined Apr 4, 2023 (3y ago) · 18 submissions

Submissions

comment 11mo ago · link · parent

Interesting. Are you talking about the latency to spawn new workers, or getting data from the main thread to the worker? To give you an idea, this library uses a lazily initialized thread pool (thread-per-core by default), where tasks are shared between workers (like the Tokio library in Rust). This means workers only need to be initialized once, and passing data via structured clone is usually very fast and optimized in most engines. Better yet is to use ArrayBuffer or SharedArrayBuffer, which can be transferred or shared between threads without any serialization overhead.

comment 11mo ago · link · parent

It was a design decision to make the syntax feel as familiar to Rust as possible. But I do agree that it's a bit verbose and that it won't hurt to add a .dispose() handle to the objects themselves.

comment 11mo ago · link · parent

I added a bit more information about Bun compatibility:

> While Bun is supported and Bun does support the `using` keyword, it's runtime automatically creates a polyfill for it whenever Function.toString() is called. This transpiled code relies on specific internal globals made available in the context where the function is serialized. Because the worker runs in a different isolated context where these globals are not registered, code with `using` will fail to execute.

4.

The missing standard library for multithreading in JavaScript(github.com ↗)

136 points · by W4G1 · 11mo ago · 35 comments

5.

The Temporal Dead Zone, why TypeScripts codebase is littered with var statements(vincentrolfs.dev ↗)

5 points · by W4G1 · 1y ago · discuss

6.

eval_macro: A New Way to Write Rust Macros(github.com ↗)

9 points · by W4G1 · 1y ago · discuss

comment 2y ago · link · parent

Creator here. Yes it's a wrapper around the Web Worker and Node Worker Threads API. In order to create an inline worker, the user provided function is serialized using .toString() and any provided yield statements (which specify outside variables, functions & imports) are extracted. Because JavaScript objects are passed by reference, we can get the references by running the user function on the main thread first (iterating over each yield statement), and stop on the last yield so the main thread doesn't execute the rest of the function. Then, whenever a thread mutates a shared variable, the new value is send or transfered to the main thread, which then updates the variable using the object's reference.

8.

JavaScript Multithreading (2023)(github.com ↗)

17 points · by W4G1 · 2y ago · 8 comments

9.

Multithreading: A JavaScript Worker abstraction to threadify plain functions(github.com ↗)

5 points · by W4G1 · 2y ago · discuss

10.

Multithreading: A tiny cross-platform JavaScript parallelization runtime(github.com ↗)

2 points · by W4G1 · 2y ago · discuss

11.

Halo: A non-invasive neural device to stabilize and induce lucid dreaming(propheticai.co ↗)

1 points · by W4G1 · 2y ago · 1 comment