DEV Community

loading...

Discussion on: 60fps Javascript while you stringify, parse, process, compress and filter 100Mbs of data

Collapse
calvintwr profile image
calvintwr • Edited

Ok I understand now. It’s all about the requestIdleCallback.

What got me interested is because I have a repo at github.com/calvintwr/blitz-hermite...

It is a client-side JS image resizer, which is overall performant in context of downsizing huge client images (DSLR whatever just bring it), before transmitting it over to the server for storage. Time difference saved is from uploading the massive image to the server, and sending back a resized version to the client. Almost all online resizers/social media sites do this slower server-side resizing, I really wonder why.

In Blitz, I’m using a worker to do the resampling, but it glitches when the worker sends back the completed work, albeit just for a short while. I might think about how to Coroutines this.. hah.

Collapse
miketalbot profile image
Mike Talbot Author

Right well if you can encode it using a Uint8Array in the worker, there's a version of JSON parse that can handle them and you can use transferrable objects with Uint8Arrays that should be near-instant. Of course, you could do anything else you like with the array using a generator based coroutine.

Collapse
calvintwr profile image
calvintwr

Ahhh yes that can work. Although the next challenge is to part out your async json parser because I shouldn’t want to bring in the full js-coroutines library just to do that part.

Thread Thread
miketalbot profile image
Mike Talbot Author

I think you could probably just get away with the coroutine runner in this article and not bother with js-c, that's probably a few lines of code that will deal with your requirements.

Thread Thread
calvintwr profile image
calvintwr

Thank mate you are awesome!

Thread Thread
calvintwr profile image
calvintwr

I found out that Uint8Array is not a transferrable object, is it? developer.mozilla.org/en-US/docs/W...

But ArrayBuffer is. And ImageData has property .data.buffer that is ArrayBuffer, so i have used that to transfer between the main and worker thread: github.com/calvintwr/blitz-hermite...

✌️👍