arv

arv

@arv.tools

Partner at rocicorp.dev, building zero.rocicorp.dev Ex V8, Chrome, TC39, Gmail, Gears

120 followers161 following56 posts

View full thread
View full thread

How it works: the compiler turns struct syntax into plain JavaScript. Shared structs live in one SharedArrayBuffer heap that every worker attaches to, and each one is a Proxy over its slots in that memory.

With TypeScript it goes further. Where the types prove that an object is a shared struct, the compiler drops the Proxy and reads and writes the heap directly. The slower Proxy path runs only where it can't prove that.

```js shared struct Counter { count = 0; lock = new Atomics.Mutex(); } ``` Pass a Counter to a worker and it gets the same object, not a copy. Take the lock with `using _ = Atomics.Mutex.lock(c.lock)` and count away.

View full thread

A checker on TypeScript 7 proves the rules: no use after a move, no mutable object reaching two threads. A Vite plugin compiles shared structs down to typed-array reads and writes.

Why the opposite? I first tried Porffor’s model in plain JS on Web Workers. Workers can’t share V8 objects, so an object had to move into shared memory as soon as a second thread could see it. It worked, but reading a shared object got ~17x slower.

So now every value is one of three kinds: • owned by one thread, and it moves • deeply immutable, copied once per reader • a struct or SharedArray, laid out in shared memory Ordinary code is plain JS. On 8 threads, Mandelbrot runs 7.6x faster than single-threaded JS, and N-body 4x.

TIL: Prefer `Float64Array` over `Array<number>` when you care about sorting. Sorting the former is a lot faster.

This might seem like it so fast that it does not matter... but... Hermes.

And here is the Hermes graph. Note that the actual numbers are not representative since this was run on iOS simulator on a MacBook M5. In reality old Android phones are at least 5x slower.

TIL: Prefer `Float64Array` over `Array<number>` when you care about sorting. Sorting the former is a lot faster.

TIL: Prefer `Float64Array` over `Array<number>` when you care about sorting. Sorting the former is a lot faster.

Also, unfortunately `TypeArray.prototype.sort` does not use TimSort... Not sure why???

arv reposted

Jarred Sumner experiments with multi-threaded JavaScript 🧪 Filip Pizlo's "wild thought experiment" from 2017 is brought to life 🔥 Unlike existing approaches (workers, SharedArrayBuffer) this shares the JS heap. It means threads directly access the same JS objects. github.com/oven-sh/WebK...

arv reposted

I wanted an app that would let me see my remaining Codex and GitHub Copilot usage quotas as easily as I can see my remaining battery life. Prompted Codex, went to the gym, came back to this. Nice.

arv reposted

arv reposted

A nine-year-old CSS spec issue has been resolved! 🎉 `position: sticky` now tracks the nearest scrolling container per axis. Want to stick an element to a scroll container AND the document? Soon possible. Chromium only for now, but great to see this land! https://www.bram.us/2026...

This RegExp is O(1) if the string is `SeqOneByteString` 🎉 ```js const isOneByte = !/[^\x00-\xff]/.test(str); ```

However, if the string is a `SeqTwoByteString` and large it has to do a linear scan which of course is not so fast. Anyone have any tricks up their sleeves to detect if a string is a a two byte string in O(1)?

Banda Bassotti@orpach.neocities.org

Opensearch is such a good feature, it's a shame nothing besides firefox supports it anymore. (you can right-click on the URL bar to easily add it on npmx.dev) In chrom*, they expect you to use an extension per search engine or manually add the replacement string in the settings window.

I really like where @remix.run is going in v3. So much less magic and using the platform for its strength. Disclaimer: I designed and implemented ES6, custom elements, shadow dom, some "modern" dom apis (classList, template element, append, remove...), making EventTarget concrete etc...

View full thread

I really like where @remix.run is going in v3. So much less magic and using the platform for its strength. Disclaimer: I designed and implemented ES6, custom elements, shadow dom, some "modern" dom apis (classList, template element, append, remove...), making EventTarget concrete etc...

One thing that I'm a bit unclear on at this point is `update`. Based on the presentation all it did was rerender but what does it mean to rerender? What about DOM state (selection, scroll position)? What about JS state?

I really like where @remix.run is going in v3. So much less magic and using the platform for its strength. Disclaimer: I designed and implemented ES6, custom elements, shadow dom, some "modern" dom apis (classList, template element, append, remove...), making EventTarget concrete etc...

arv reposted

I know this first hand. When I was a child, my entire community was branded as spies and sabateurs, justifying our internment inside barbed wire camps for years without due process, trial or charge.