July 9th, 2024

Show HN → Parallel DOM: Upgrade your DOM to be multithreaded

Parallel DOM accelerates web apps by parallelizing heavy DOM tasks. It integrates easily, runs React components concurrently, and ensures security through sandboxed iframes. Users can self-host or deploy with Vercel.

Read original articleLink Icon
Show HN → Parallel DOM: Upgrade your DOM to be multithreaded

Parallel DOM is a tool designed to speed up web applications by parallelizing heavy DOM operations. It offers a simple API for easy integration into existing code, ensuring secure execution within a sandboxed iframe wrapper. By dedicating a CPU process to JavaScript and DOM manipulation, Parallel DOM enables running React components in parallel. Users can self-host Parallel DOM or deploy it with Vercel, with detailed instructions provided for setup. The tool addresses concerns about security, explaining how it utilizes sandboxed iframes and in-browser script injection to protect against vulnerabilities. Unlike Web Workers, which lack access to the DOM, Parallel DOM focuses on optimizing DOM manipulation tasks. While the tool is available for use on the provided domain, users have the option to host it themselves, leveraging its open-source nature and documentation. Parallel DOM emphasizes its compatibility with various static hosting providers, making it a client-side solution without the need for a backend server.

Related

Understanding React Compiler

Understanding React Compiler

React's core architecture simplifies app development but can lead to performance issues. The React team introduced React Compiler to automate performance tuning by rewriting code using AST, memoization, and hook storage for optimization.

Understanding React Compiler

Understanding React Compiler

React's core architecture simplifies development but can lead to performance issues. The React team introduced the React Compiler to automate performance tuning by rewriting code. Transpilers like Babel convert JSX for efficiency. Compilers, transpilers, and optimizers analyze and produce equivalent code. React Compiler enhances functionality using Abstract Syntax Trees, memoization, and hook storage for optimized performance.

New Web Development: Or, why Copilots and chatbots are bad for modern web dev

New Web Development: Or, why Copilots and chatbots are bad for modern web dev

The analysis critiques Copilots, chatbots, and React for web development, citing slow sites, complex code, and high costs. It advocates for a shift to browser APIs, CSS, and HTML for better performance and lower expenses. Transition challenges include finding developers skilled in vanilla JavaScript. Organizations are urged to prioritize simplicity, efficiency, and core web technology training.

Show HN: A JavaScript UI library for imperative JSX

Show HN: A JavaScript UI library for imperative JSX

The @matry/dom npm package introduces a web framework for imperative JSX, aiming to enhance UI engineering by offering a more imperative approach compared to React. It provides control over rendering and flexibility in UI design. Developers are cautioned against using it in production before version 1.0.0.

Execute JavaScript in a WebAssembly QuickJS Sandbox

Execute JavaScript in a WebAssembly QuickJS Sandbox

QuickJS is a secure JavaScript execution tool in a WebAssembly sandbox. It includes security features, file system access, custom node modules, a fetch client, and a test runner. Find detailed documentation and examples in the repository. Users can seek further assistance for inquiries.

Link Icon 20 comments
By @sakras - 5 months
The demo fell a little flat because the "before parallel DOM" and "after parallel DOM" boxes were almost exactly in sync for me (Firefox, MacOS).
By @eyelidlessness - 5 months
It seems the “threading” mechanism depends on the browser’s own process model? As in, you’ll get another “thread” iff the browser creates a separate process for the cross-origin iframe?

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.

By @XCSme - 5 months
I don't understand what it does and why.

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.

By @raggi - 5 months
classic web engineering demo:

  - 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?
By @theogravity - 5 months
Requesting performance isolation with the Origin-Agent-Cluster header:

https://web.dev/articles/origin-agent-cluster

By @halyconWays - 5 months
We've strayed too far from God's light. Return to Gopher.
By @chrisldgk - 5 months
For anyone interested, I made a public Docker Image of the "backend" (which is basically just and index.html and a JS file)[0].

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

By @pragmatic - 5 months
I think you’re burying the lede here.

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?

By @apatheticonion - 5 months
It's crazy that people say that WASM won't replace JavaScript. This demonstrates a use case better suited for languages with better threading models than JavaScript.

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!?

By @ks2048 - 5 months
The demo is computing prime numbers - what does that have to do with the DOM?
By @Nathanba - 5 months
pretty interesting, Origin-Agent-Cluster only exists on Chrome/Edge so far though and it sounds like it is only intended as a browser hint. From the example I don't quite understand though: Why would the non-parallel version already be so laggy if it runs on the mainthread (1 thread, nothing much else happening on the page) versus the iframe-parallel version which also just gets 1 thread right?
By @eacapeisfutuile - 5 months
Please no, this is a solved problem for decades, it will not actually multithread the DOM and more likely just add overhead.
By @btown - 5 months
See also: https://github.com/krakenjs/zoid which allows you to present a simple interface to sites that want to embed your application and send parameters/register callbacks. All the caveats of frames still apply, of course, and scrolling glitchiness alone is a reason to avoid frames altogether... but if you absolutely need to present your application as a frame, it's a developer-friendly way to do so.

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.

By @fabiofzero - 5 months
Firefox on M1 Max. After Parallel DOM is slower here.
By @gshklovski - 5 months
Worker threads are so frustrating. Good work
By @xori - 5 months
Why reach for iFrames over other technology like WebWorkers?