nitish24p / react-worker-image

React component to fetch image resources via web workers 🤖🤖
MIT License
232 stars 18 forks source link

Is spawning a new worker for every image a good idea? #10

Open kurtextrem opened 6 years ago

kurtextrem commented 6 years ago

See title. I don't really have experience with those, but shouldn't be one worker sufficient? I imagine loading 50+ images via 50 workers is slower than loading 50 images with 1 worker

nitish24p commented 6 years ago

Yes this had come up into my head. Browsers offer support for using shared workers instances, so can try that or can terminate the worker once the inage has been downloaded.

nitish24p commented 6 years ago

@manjula91 thoughts..

kurtextrem commented 6 years ago

I'll ask Benedikt Meurer on Twitter, he's a v8 performance engineer. https://twitter.com/kurtextrem/status/962234931400335367

I'd guess when we spawn more than OS CPU cores - 1 (as one core is used already by the main thread), we probably have no benefits or a negative impact. But let's find out, I'm curious as well :)

manjula-dube commented 6 years ago

shared workers can be given a shot here

manjula-dube commented 6 years ago

@kurtextrem Lets find out how impact full it will in this case?

kurtextrem commented 6 years ago

What would be the difference in our case between those two? The only difference I can see is "[Shared Workers can be] accessed from several browsing contexts, such as several windows, iframes or even workers" I think we should continue using Web Workers, especially as Apple / Safari dropped Shared Workers support, and instead of spawning them in each component, we should spawn them outside or in a factory that decides whether enough have been spawned or not.

manjula-dube commented 6 years ago

Fair enough i think that sounds great. Would you want to take this up @kurtextrem ?

kurtextrem commented 6 years ago

@manjula91 I'd like to wait for Benedikt's opinion first, but I'd love to do this for sure afterwards! :)

manjula-dube commented 6 years ago

cool 👍