HNHacker News
TopNewBestAskShowJobs

dassurma

289 karma · joined October 15, 2017

[ my public key: https://keybase.io/surma; my proof: https://keybase.io/surma/sigs/FpZ-zMW2qZbl6VdJbyjr5mpkKqwQUuGIOsl8OMW6iSM ]
submissionscomments
dassurma··on When to use web workers
If you take a look at the issues on the repo, a lot of people agree with you. The syntax was not final at all, we need to convince TC39 first before we can start bikeshedding ^^
dassurma··on When to use web workers
Why do you think it's less reliable? setTimeout gets clamped by the browser to a minimum of 4ms, so you waste a lot of time when all you want is a task boundary.
dassurma··on When to use web workers
All your logs are executed immediately. .then() takes a callback function!!

FYI: AsyncTask and MicroTask are equivalent, and so are my task() function and your OnMessageTask

dassurma··on When to use web workers
OffscreenCanvas is exactly that! It's standardized, but only chrome has implemented it so far, sadly.
dassurma··on When to use web workers
IndexedDB is shared between workers and main thread, in case that helps.
dassurma··on When to use web workers
The problem is mostly in that all these functions are closures, and scope can’t easily be transferred.

Domenic and I have been working on a proposal[1] called Blöcks to introduce transferable functions to JavaScript.

In the meantime, I wrote Clooney[2] ontop of Comlink[3] that gives you almost that.

[1]: https://github.com/domenic/proposal-blocks

[2]: https://github.com/GoogleChromeLabs/clooney

[3]: https://github.com/GoogleChromeLabs/comlink

dassurma··on When to use web workers
We are using loads of Wasm in Workers in https://squoosh.app

Since Wasm is synchronous, I’d say it should almost always be run in workers except if the module needs access to some main-thread-only API.

dassurma··on When to use web workers
Agreed. I am quite annoyed that no browser has shipped modules in workers. There is little incentive as Workers are sorely underused.

Since I mostly use rollup, I ended up writing a plugin[1] that allows you to pretend that modules are in workers. It compiles down to AMD under the hood and uses a very minimalistic worker.

[1]: https://github.com/surma/rollup-plugin-loadz0r

dassurma··on When to use web workers
Yes, that’s exactly what AnimationWorklet is for.

That being said, I think even smaller-scale things like state management and hitting APIs should be moved to workers. It all increases resilience and buys headroom for low-end phones.

dassurma··on When to use web workers
Ah, no Svelte was around, but we were on a pretty tight deadline and had a good amount of experience with Preact in the team. We didn’t feel comfortable increasing the risk by using an unknown framework.
dassurma··on When to use web workers
I have played with Svelte, not used it for any project yet.

When you say, “this site”, do you mean my blog? Because that one’s fully static using 11ty.

dassurma··on When to use web workers
I never claimed that Web Workers are the silver bullet that will absolve us from all our problems. On the contrary, I don’t think such a silver bullet will ever exist.

I am saying that we should be using web workers to keep the main thread free. That is completely orthogonal to good static design, proper bundling, right caching headers, code splitting, asset hashing etc etc.

dassurma··on When to use web workers
It's still costly, but at least it'd not be blocking the main thread. I'd definitely give it a try!
dassurma··on When to use web workers
You could always use transferable ArrayBuffers and serialize your data with Flatbuffers or something similar.

That being said, in all the off-main-thread apps I have written so far, the cost of structured cloning was pretty much irrelevant.

dassurma··on When to use web workers
Static _is_ better for a good bunch of performance metrics. But what about interactive content like https://proxx.app?

The article is mostly aimed at use-cases where some sort of logic in JavaScript is required.

dassurma··on When to use web workers
Agreed. I personally find BroadcastChannel more flexible, but they are not in Safari either :(
dassurma··on Compiling C to WebAssembly Without Emscripten
I consider myself aesthetically handicapped, so this comment made my day. Thank you very much.
dassurma··on Compiling C to WebAssembly Without Emscripten
Agreed! WASI is the logical next step. It’s the “universal glue code” I wanted to have for the longest time.
dassurma··on Compiling C to WebAssembly Without Emscripten
Author here :) I am very excited about WASI, but as I mentioned in a comment below, wanted to keep it to the fundamentals so you can appreciate what WASI does for you.

And definitely agree with the shout-out to Twiggy (which I mention in the previous post in the series)!

dassurma··on Compiling C to WebAssembly Without Emscripten
Author here :D WASI is great and has me all kinds of excited, but I wanted to cover the fundamentals so people can appreciate what WASI really gives you.
dassurma··on Replacing JavaScript Hot Path with WebAssembly
Go was pretty much a non-starter. They (currently) need a runtime which will make the file size non-competitive to the other ones. Also, since only Chrome has support for threads in WebAssembly (in Canary), we’d not be able to make any use of the concurrency.
dassurma··on Replacing JavaScript Hot Path with WebAssembly
I did :D Turns out compilers are pretty good at generating WAT.
dassurma··on Replacing JavaScript Hot Path with WebAssembly
Huh interesting! I always disliked butchering code to do processor cache optimizations and I kinda worked under the impression that a browser’s JS and wasm compilers would do these optimizations for me.

I’ll definitely give tiling a spin (although at this point we are definitely fast enough™️)

dassurma··on Deep-copying in JavaScript
I kinda agree, although I think "epic failure" is a bit strong. But that's exactly why I am volunteering to work on the spec to move that functionality into the HTML spec, and then hopefully also to ECMAScript.
dassurma··on Deep-copying in JavaScript
As I explain in the article, postMessage does not stringify. It runs the structural clone algorithm, as per spec. Otherwise things like ArrayBuffers, Sets et al. would not make it to the other side.
dassurma··on Deep-copying in JavaScript
So, it’s me being lazy and copy-pasting, but you can use await on synchronous functions, too. It’s a no-op :D
dassurma··on Deep-copying in JavaScript
Ohai. Author here. That’s indeed one of the trip-wires. So is that any kind of prototype is lost.

The point of the structured clone algorithm is to make values transferable to other realms, so functions are actively ignored. Most of the time, I think that is “good enough”.

dassurma··on CSS Paint API: New possibilities in Chrome 65
... my bad. Last minute corrections made it worse. Will get it fixed ASAP.
dassurma··on CSS Paint API: New possibilities in Chrome 65
Author here :)

Houdini is a task force that consists of people from Apple, Mozilla, Microsoft, Chrome, even IBM and Samsung. It’s by no means a Chrome-only thing or us being pushy.

Servo has an experimental implementation, but it’s the part of Servo that hasn’t been merged into FF. All participating browser vendors have given very positive signals about CSS Paint API.

Check http://ishoudinireadyyet.com/ to stay up to date :)

dassurma··on Tasklets: a more ergonomic solution to WebWorkers
> If Chrome’s implementation of web workers is too heavyweight, that’s Chrome’s problem.

You absolutely have a point. Ben Kelly from Mozilla pointed out to use that their workers are _much_ cheaper than ours. We apparently never invested much time in optimizing Workers as they are rarely used.

← PreviousPage 2 of 3Next →