Show HN: Parallel DOM – Upgrade your DOM to be multithreaded
pdom.dev
pdom.dev
It does seem to work in Chrome though.
> What browsers are currently supported ? Since we depend on the `Origin-Agent-Cluster` header being honored by the browser, we are currently limited to Chrome and Edge.
After a while the computations get harder to the point that one of the square's animations starts to become janky, while the other stays smooth.
This example is not intuitive.
The square should be more prominent than the graph, otherwise users will think that they're supposed to be looking at the graphs.
I am an FF user myself and super sad to see that :(
That’s a clever hack where it works. For what it’s worth, it doesn’t seem to work on mobile Safari, at least judging by both examples slowing down at roughly the same rate. In which case, the “parallel” example is very slightly slower, presumably due to marginal overhead of the cross-frame mechanism.
What kind of DOM computations are so intensive they need to be parallel?
Most intensive computations are done in JS, which is not related to the DOM and can be ran in Web Workers if you need parallel execution.
If they are so heavy, shouldn't the vizualization be WebGL? The DOM is for hierarchical information.
For eg, a testrail plugin for JIRA or a diagramming plugin on Google Docs.
You would want to run these plugins in their own DOM so that they don't accidentally slow down the main app.
- small well contained math operation that could be put in a worker
- instead of putting that in a worker, startup a whole parallel page and shuttle messages via ipc for the heaviest part of the process, redoing a lot of the work twice
why are the solutions always backward?This should make self-hosting a bit easier. You can also find the GitHub repository for the (pretty simple) Dockerfile on GitHub[1].
[0] https://hub.docker.com/repository/docker/uninspiredstudioops...
[1] https://github.com/UninspiredStudio/parallel-dom-docker
Edit: Formatting
It looks like you have the ability to run an isolated portion of the dom on another thread and you can communicate with it with this library? Am I close?
I think more examples could help. Could you have 2-3 real time analytics viz/charts running in 2-3 different threads? Is this mostly for desktop or does mobile benefit also?
You could run any number of parallel threads.
This is applicable on both desktop and mobile.
Feels like the web world is desperately in need of competent threading capabilities. Can I (practically) use Rust or Go in the browser via wasm already!?
>big web apps
So you've defined the goalpost as "big web apps". There are billions more use cases for Javascript than however many "big web apps" might exist. So your phrasing is too broad, maybe consider:
>>It's crazy that people say that WASM won't replace JavaScript in big web apps.
Nobody's saying that. You are free to use WASM for your "big web app". Nobody and nothing is stopping you.
WASM certainly has its place, but it also certainly won't replace JavaScript in most of the places JavaScript is used every day. "Big web apps" are (my guess) maybe 1,000,000 of the 49,501,698 websites that use JavaScript, but it would depend on how you define "big web app" (and I really don't want go down that goal-posting rabbit hole). There are 13.8 million people writing javascript every day, how many of them do you think are working on "big web apps" that actually need WASM? How many of them do you think want to switch to Rust from Javascript? "developers" always seem to think everyone else should be some rockstar 10x programmer, but most use cases for javascript are pretty simple, and yet totally effective for what the requirements typically are.
I don’t think everybody needs to be building big web apps, I just think that most full time developers writing JS (or TS) are probably on a team working on a web app, so the introduction of a build process isn’t really an issue.
Of course it’s valid to write good ol’ javascript. I do it all the time. I’m always happy to avoid dealing with webpack
But to answer your question, yes you can use Rust and Go practically in the browser. It just isn’t all that helpful except in narrow circumstances.
The difference with Rust and Go is they have better synchronization capabilities - where JavaScript largely forces you to clone data between threads.
So while you may still be messaging worker threads in Rust/Go - threads share memory which is fast and you have access to things like atomics and mutexes.
We can use Rust in the browser today with WASM and it's super cool - but without something like WASI, extensive thunking through JavaScript is required, plus there are issues with threading.
I hope that one day we can initialize a wasm module via a script tag with the browser offering a wasi interface
`<script src="module.wasm" type="application/wasi">`
And that browsers allow for threading without the restrictive security headers we have today
https://github.com/WebAssembly/threads/blob/main/proposals/t...
But that’s not going to help when accessing the DOM.
Is there a proposal(s) covering DOM access?
I remember interface types were a thing a few years back. If you have access to a dom object (I assume by pointer?) and it is removed/GC'd - would the wasm module have a null pointer?
Isn't that what SharedArrayBuffer is for (avoiding)?
Again, there’s very few actual uses for wasm. The main one is when you have a preexisting library in a different language, other than that you don’t gain any real functionality from using it.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
In the past I have used a SharedArrayBuffer to store a custom Graph implementation sent between threads. I stored the adjacency list in the SAB with the rest of the data being stored as a plain object and cloned/sent via postMessage between threads.
This worked but is extremely janky, required an unsafe custom data structure, manual/unsafe memory page management, was difficult to read/review and the performance was lacklustre because half of the data structure was plain JS objects that needed to be serialized and cloned anyway.
Simply, JavaScript sucks for multithreading and it would be great to have the ability to write high performance, multithreaded, complex web applications in a language designed with parallelism in mind - like Rust or Go.
While wasm _today_ cannot offer that (at least not practically) - there is certainly a use case for replacing JavaScript in that context and I hope that it does.
JS will still be useful for basic applications that just need a little scripting
I must question whether the problem of random sites wanting to spin up a whole ton of cores that consume arbitrary amounts of compute and memory really needs to be solved.
You can use “WASM threads” from Rust or Go. Or JavaScript for that matter. Under the hood it’s all workers and shared array buffer, nothing to do with the language. Last time I checked you can’t even use std::thread for instance in Rust, since the compiler doesn’t understand workers (because workers aren’t actually part of WASM).
None of which will help you when updating the DOM anyway, since that happens in its own thread. It’s up to the browser how they run their rendering engine and I doubt they’re ever likely to allow direct control over that.
You can (built into rust and tinygo for go.)! And wasm-threading has been around for a while! https://webassembly.org/features/ But I don't think these wasm-threading capabilities are well harnesses by any languages yet.
There been a decade of webworkers being super possible. That does get multi-threading! With transferable memory & everything. So, this isn't like some new super non-js thing. Some folks do use workers, but alas not popular enough, not something React or Angular helps steer folks to.
Whats super neat and tricky here is that the iframe in separate origin-agent-cluster has a full DOM implementation that's there & raring to go. We already could have tried using jsdom or happy-dom or a wasm-powered alternative in a worker to do something like this, already. This is super cool though because it's much lower code! It uses a dom runtime that's already loaded & available (the browser's) rather than having to ship & load a separate DOM runtime.
Pdom seems to be a way to do that to yourself, if you can't trust that your content won't cause performance degradations and you absolutely want the context outside that content to stay responsive. I'd only use it, and really any frame, for components where the size is known ahead of time, though; asking a frame to resize itself to fit its contents, when its contents may themselves be resizing to the size of the frame, is a recipe for disaster. Which brings me around to why I try to avoid frames for anything user-facing when at all possible.
I find it an interesting choice that the author decided to invest in new iFrame technology rather than existing multi-thread technology in the browser.