Thanks a lot for the feedback everyone, that's super helpful!
> Note that for extensions that observe user activity keeping the
background script alive is not detrimental to the browser's resource
usage, on the contrary, it's much better than restarting the worker
hundreds of times a day because each restart is an extremely heavy
operation that stresses CPU, memory, disk, and wastes battery life.
Wow,
does it seriously get put to sleep and woken-up every single time? That
sounds horrible... Isn't Chrome supposed to do some kind of
optimization to keep the worker alive as much as possible?
And since we are on the topic, is there any official documentation regarding when a worker is put to sleep?
My naive guesstimate is that chrome will put the worker to sleep if there is no event activity for X minutes.
Could it then be converted into a persisting background worker if I am dispatching an alarm every minute? 😁
> Unfortunately, the official documentation and other official
communications still retain the generally false claims that a persistent
background script is bad for performance and/or resource usage, but
it's an understandable mistake as there apparently has never been a
single person in the Chromium team who performed proper performance
measurements in this area.
Well, I see the good
intentions behind MV3, but I don't see it being thoroughly thought.
(and considering that Google is not lacking intellect, I am assuming
there are business decisions behind it)
To
be more precise, if your extension is not implementing any serious
business logic (and therefore your service worker is small), the MV3
implementation makes total sense: instead of having a persistent JS VM
running all the time, waking-up your worker just to handle an event
sounds like a sensible way to reduce the resource footprint... and honestly, since the majority of the extensions are simple enough to fall into this category, I do see the value.
However,
if you are implementing any kind of more complex logic you are more or
less doomed: your service worker becomes too heavy for being constantly
restarted, you have no capabilities for starting web workers, and you
have to resort to ugly workarounds to deliver your functionality. This
is too obvious to be a bad decision... (and considering how easy it is
to run your business logic on GCE and interface with your extension
using GCM (now FCM), it kind of gives you an idea of the intended future
direction).
Obviously, extensions that are dealing with private data will never be able to migrate on the cloud, so they will be forced to use ugly workarounds, use native binaries, or simply retire...
From my PoV, since I am also developing something that falls under the last category, I would have been immensely happy with MV3 if:
- The service worker state was persisted and restored by chrome between sleep cycles (that will greatly improve the worker start-up time)
(Or simply introduce a permission that will allow the service worker to persist forever)
- There was an API that would allow me to spin multiple Service Workers in the extension domain, in the same way I could spin Web Workers (this will improve the parallelization on heavyweight local tasks)
I am actually willing to invest the time to contribute these features to Chrome myself, but I have no idea about the contribution process there 😁