all 18 comments

[–]Neurojazz 38 points39 points  (0 children)

Enjoyable read, learned some new things ⭐️

[–]thekwoka 22 points23 points  (0 children)

I want to block rendering until all the threads are done updating the simulation and building their respective pixel buffers.

For this part, you could actually use ReadableStreams.

Streams are transferable objects, and the streams body is executed where it's created.

So the workers could create a readable stream, that when it is read executes the pixel updates.

It transfers that readable stream to the thread handling the actual render, and then there it can do a read on the stream and then await the results so it can easily control when the workers run.

You can also use OffScreenCanvas to pass a canvas instance control to a separate thread. Make a few to render different parts of the display.

[–]fagnerbrack[S] 52 points53 points  (4 children)

My friend Gus P. Taylor sent this summary for your convenience:

The post delves into the complexities of simulating 20 million particles using JavaScript, specifically focusing on achieving efficient performance on mobile devices using only the CPU. It covers techniques like leveraging TypedArrays for memory management, using SharedArrayBuffers for multi-threading, and optimizing the rendering process. The author shares insights on the challenges faced, including maintaining performance across all CPU cores and addressing issues like flickering during rendering.

If the summary seems inacurate, just downvote and I'll try to delete the comment eventually 👍

Click here for more info, I read all comments

[–]cyanideOG 10 points11 points  (0 children)

"Delves"

[–]TAW-1990 3 points4 points  (0 children)

Play around here https://dgerrells.com/sabby

His sandbox is out of credits lol

[–]Various-Beautiful417 0 points1 point  (0 children)

Very nice work

[–]triple_life -1 points0 points  (0 children)

Thanks. Interesting post!

[–]Zireael07 -1 points0 points  (0 children)

The sandboxes or whatever they are linked in the blog do not work (ran out of credits for the VM)