Re: [slightlyoff/ServiceWorker] consider allowing multiple worker thread instances for a single registration (#756)

> I think I'd like to hear more from the other browser vendors before spending more time on this right now. Internally we have decided to proceed with our "single SW thread across multiple processes" implementation for now.

I don't think we should give up on this just because it introduces complications to certain APIs such as `postMessage()`. As you mentioned, perhaps we should really be thinking of service workers as worker pools. There shouldn't be a guarantee that a service worker instance that just handled an event would be the same one that would handle the next event, including `onmessage`. This goes back to the idea that you can't take a dependency on global state because it was never guaranteed to you to begin with due to varying implementations and policies for terminating service workers.

While I understand that this complicates matters for developers, the fact of the matter is that service workers were always intended to be ephemeral and browser vendors are supposed to be able to do the "right thing" depending on device constraints such as memory, CPU, and battery. In the same way that browsers should be able to coalesce service worker instances to limit system pressure, they should also be able to optimize for devices that can afford resources to concurrently run the same service worker script in multiple instances. These are optimizations that the browser will make on a developer's behalf to make their app or site more robust. For developers to buy into this model, they need to ensure that their service worker is truly not relying on state between events being handled.

One other concern here is around developers relying on events being handled in sequence instead of in parallel. For instance, a fetch may do some work in its event handler that's needed by a subsequent fetch handling. Although there may be some optimizations that a developer can make here, perhaps it really shouldn't be supported because, as mentioned earlier, it would be bug prone due to differing implementations and it would limit the ability for a browser to parallelize execution.

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/756#issuecomment-238985247

Received on Wednesday, 10 August 2016 19:58:46 UTC