Html: Remove shared workers?

Created on 6 Nov 2015  Â·  60Comments  Â·  Source: whatwg/html

Both Apple and Microsoft are against implementing them I learned. They are rarely used. There is reportedly some usage on Google properties and Firefox OS may use them, neither seems super persuasive.

Should probably add a deprecation warning to start.

removadeprecation workers

Most helpful comment

I think this is generally a bad idea. It's also very sad that SharedWorker is underestimated everywhere, including those leading browsers like Chrome, Edge or Safari.

SharedWorker encourages developers to build well architectured web apps. Without SharedWorker, things like persistent connections (including WebSocket and WebRTC connections), single connection to database, emitting messages to multiple web pages are almost impossible. All these features are not mandatory for traditional web applications, where AJAX, session, cookies and other old technologies are still the king. But this is not the case for modern, offline web apps, which should be designed with a modern architecture instead.

picetalk application architecture

The above design will highly improve the efficiency of web apps. Not to mention about their AJAX-lessness, the entire application data can now be managed by a single thread. Main threads are just for rendering user interfaces. That means only DOM and CSS are being executed on a web page. User experience will be vastly improved as a result. Using SharedWorker intializes an extra thread, but it will reduce a huge amount of required resources of both server side and client side. Application using WebRTC might even gain more benefits from using SharedWorker.

In my opinion, not only supporting SharedWorker, but browser vendors should also encourage developers to implement it on modern web applications, which will absolutely be dominant in the near future.

All 60 comments

Personally this seems premature to me. Maybe once an alternative like foreign fetch exists it might be possible, but until then what are the reasonable alternatives?

Here is the use case from Firefox OS:

Apps in Firefox OS can have multiple windows open against them. One could be serving as the main app window, one could be in use by a web activity, part of another app flow.

We want to run the backend data services in a shared worker:

  • Saves memory/resources vs multiple workers.
  • Logical code isolation for backend development. Knowledge that only one instance of it will be active simplifies development.
  • Allows gating or serializing IO work in one location. This is particularly useful in the email app on FirefoxOS, where it uses mozTCPSocket to talk to mail servers. We only want one thing in the browser doing that work.

Additionally, we would like to see the ability for a Service Worker to use the same Shared Worker for Service Worker entry points like background sync, for the same reasons above.

In the Service Worker example, there may or may not be an existing window open for the email app, and we do not want to take the hit to create one just to create a worker. Ideally the Service Worker could trigger spinning up the Shared Worker. If it is already running, just communicate with it. If a browser window for the app is created while the background sync is running, it would just communicate with the Shared Worker that could already be running.

More in-depth notes on how the Firefox OS SMS app uses a shared worker

If Shared Workers are going away, it would be helpful to know what mechanism is available to achieve similar results.

One more important use case for the Firefox OS SMS app is that code hosted inside SharedWorker could potentially create in-memory data view (e.g. based on the data extracted from IndexedDB) for the super fast access.

The app itself will consist of several pages, every page is a separate document, to navigate between pages we'll use real links that will navigate user from one document to another and it's important to keep this in-memory data view alive between navigations so that page2 will use the same in-memory data view created by page1 almost for free.

IIRC SharedWorker is kept between page navigations if they are bound to the same domain, please correct me if I'm wrong. BFCache and Prerendering that we're going to use will likely benefit by SharedWorkers as well.

@wanderview it doesn't really matter if it's not being implemented.

IIRC SharedWorker is kept between page navigations if they are bound to the same domain, please correct me if I'm wrong.

Is that implemented? The specification allows for it in theory, though is somewhat vague on the specifics, but that was a fairly recent change.

A lot of the use cases seem to be handled fine by service workers, perhaps combined with foreign fetch.

@wanderview it doesn't really matter if it's not being implemented.

It matters if you want to actually want to convince browsers that have implemented it to rip it out.

Is that implemented? The specification allows for it in theory, though is somewhat vague on the specifics, but that was a fairly recent change.

@wanderview will know for sure, but yeah, I see that SharedWorker survives between two pages in Firefox, see example (everything is logged in console). And it doesn't work like this in Chrome Beta.

I also feel that it's a bit too early to remove it. ServiceWorker could be the alternative, yes, but as already mentioned on this thread there seem some usage ServiceWorker doesn't work really well, and it'd be probably good to investigate a bit and make it clear what usage scenarios we will be disregarding by killing SharedWorker.

One more important use case for the Firefox OS SMS app is that code hosted inside SharedWorker could potentially create in-memory data view (e.g. based on the data extracted from IndexedDB) for the super fast access.

Actually one of the use cases we hear in Chrome/Blink is something similar to this (though it's not for across page navigations in our case), having SharedWorker as a common backend for multiple pages to do efficient caching (and opening multiple pages for the site seems to be kind of common usage).

As it currently stands, Shared Workers are dramatically easier to use than Service Workers. That makes me reluctant to remove Shared Workers.

Specifically, with a Shared Worker you can simply do

w = new SharedWorker(url);

and you have a reference to an object which can provide a service though a postMessage based API.

Service Workers require that you wait for registration to happen and for resources to be downloaded. You can work around this by using a separate Service Worker with a dummy scope, to handle your database/network connections. But this feels very hacky and also means that that Service Worker can't be managed by your fetch-intercepting Service Worker.

I think this is generally a bad idea. It's also very sad that SharedWorker is underestimated everywhere, including those leading browsers like Chrome, Edge or Safari.

SharedWorker encourages developers to build well architectured web apps. Without SharedWorker, things like persistent connections (including WebSocket and WebRTC connections), single connection to database, emitting messages to multiple web pages are almost impossible. All these features are not mandatory for traditional web applications, where AJAX, session, cookies and other old technologies are still the king. But this is not the case for modern, offline web apps, which should be designed with a modern architecture instead.

picetalk application architecture

The above design will highly improve the efficiency of web apps. Not to mention about their AJAX-lessness, the entire application data can now be managed by a single thread. Main threads are just for rendering user interfaces. That means only DOM and CSS are being executed on a web page. User experience will be vastly improved as a result. Using SharedWorker intializes an extra thread, but it will reduce a huge amount of required resources of both server side and client side. Application using WebRTC might even gain more benefits from using SharedWorker.

In my opinion, not only supporting SharedWorker, but browser vendors should also encourage developers to implement it on modern web applications, which will absolutely be dominant in the near future.

I was about to learn this new feature... I hope will be interest from implementors to implement this nice feature.

@annevk The only reason we didn't use it for our apps was the lack of browser support and caniuse site reporting it as removed or not planned. We definitely wanted to implement our apps as describe by @tresdin. Please make this feature back to life and please vendors implement it in your browsers this time.

I really think the way to go here is to merge the functionality that ShareWorkers and Service Workers provide. As Service Workers are currently implemented, they are effectively Shared Workers, except you can't get to them using new ServiceWorker(url) syntax.

Instead there's a level of indirection involved, since a Service Worker is identified by a scope which in turns maps to a url, rather than a url directly.
And the syntax for getting the Service Worker doesn't use constructors.

Other than those two differences, there's very little that separate Service Workers and Shared Workers in current implementations.

@sicking ServiceWorker is vastly different from SharedWorker. ServiceWorker has a temporary life time while SharedWorker persists until all pages are closed. ServiceWorker will be automatically terminated when there is no more tasks to handle. This single point make it hardly comparable with SharedWorker.

BTW, I've already proposed the idea of merging ServiceWorker with SharedWorker by extending its lifetime. The ServiceWorker team refused to take this idea because they're afraid of ServiceWorker being blocked by background processes. I still against their point though.

I think this issue is still not as important, at least at this time. If SharedWorker is really going to be removed, the future of modern web applications won't be so bright.

My point is that current implementations of Service Workers do not in fact give them temporary lifetimes.

They are not shut down until the last page that used them is closed, the same as Shared Workers

My point is that current implementations of Service Workers do not in fact give them temporary lifetimes.

They are not shut down until the last page that used them is closed, the same as Shared Workers

This is incorrect. Both chrome and firefox shutdown the worker thread even though a controlled window is still active. See:

https://dxr.mozilla.org/mozilla-central/source/dom/push/test/test_serviceworker_lifetime.html

SharedWorkers are in-between WebWorkers and ServiceWorkers in terms of complexity. They are more functional than WebWorkers, and faster than ServiceWorkers, which have a security overhead.

Likely future designs may extend WebWorker functionality, and/or allow ServiceWorkers to operate without security. I have noticed that SharedWorkers are much slower than basic WebWorkers due to the extra thread management they require.

ServiceWorker is slowest because it requires secure Websockets (SSL), XHR and other securable endpoints.
EDIT: @indolering thanks for the heads-up, currently ServiceWorkers may only be used in secure contexts, as @asutherland notes below.

@dcerisano Although ServiceWorkers may only be used in secure contexts, this does not translate to any security overhead once they are installed. (And indeed, since HTTPS allows use of HTTP/2, sites like https://www.httpvshttps.com/ help demonstrate that they can have drastically superior transport performance.) Once installed, a ServiceWorker is exclusively served out of the browser's local storage, so network transport does not enter into things.

Both ServiceWorkers and SharedWorkers may be subject to higher communication latencies in multi-process(-capable) browsers for postMessage/friends because of the potential for cross-process communication. But they should not be any slower in their actual CPU-bound processing performance. Dedicated Workers do benefit from being easily co-located in the same process with the pages/workers that spawn them, but once cross-process-capable APIs like MessageChannel/BroadcastChannel are involved, they are subject to the same communication latencies of Shared and Service Workers.

FWIW, SharedWorkers and ServiceWorkers are critical to decentralized web efforts. But if Apple already ripped out shared workers and Edge isn't willing to implement them, then perhaps the best move would be to extend ServiceWorkers.

Shared worker are good to control multiple pages, without using a service worker. Using the least responsibility principle I claim shared worker to stay. https://en.wikipedia.org/wiki/Principle_of_least_privilege

I don't always want to create a proxy between browser and server.

@GrosSacASac Apple already added and then removed support for shared workers. Enhancing service workers might be the only way to get this functionality added to other browsers....

Chrome for Windows, Mac, Linux, Android and iOS represents over 80% of all browsers, and is increasing.

Shared Workers solve the problems mentioned above while providing a clean separation of concerns between the various worker types.

Shared Workers are being used in large scale commercial web deployments, and becoming more pervasive. The genie is not going back in the bottle that easily.

Mozilla supports Shared Workers (actually a superior implementation) as does Opera. The longer this situation persists, the less likely Google will be to change things.

The others will just have to fall in line, or risk not being able to support these new generation web apps. Keep in mind Shared Workers allow near desktop app complexity, scalabilty, and performance - people are willing to pay for web apps that do that.

ServiceWorker is slowest because it requires secure Websockets (SSL).

@dcerisano I believe that Mozilla and Google are committed to not preventing future APIs from interacting with non-encrypted communications. If anything, your basically arguing for dropping shared workers :smiling_imp:.

@GrosSacASac What if they made intercepting requests an opt-in feature?

@dinoluigivercotti Yeah! Screw 20% of users!

What if they made intercepting requests an opt-in feature? --> That would be not enough, shared worker have the ability to be multiple per page. And other features.

@GrosSacASac Yeah, that's what I figured. I guess the onus is on us to make SharedWorkers more useful. Maybe we just need to make SharedWorkers and WebWorkers less of a PITA to work with and provide a unified API.

@indolering, you could get Google to drop Shared Workers tomorrow, if you were really familiar with the actual current issues. Also, screwing 100% of all users is what Apple is doing by quietly running away from the issues they themselves discovered, rather than contributing to the opensource Chromium codebase they pulled their Shared Worker implementation from.

@dcerisano already suggested a merge of worker APIs to eliminate Shared Workers, but this is already likely too late to be practical. The APIs are not why Apple dropped Shared Workers anyway.

The Mozilla Shared Worker implementation should be adopted into Chromium. The existing Chromium Shared Worker implementation is a flawed advertiser driven hack, and being pulled into 80% of all browsers.

@dinoluigivercotti Some of us don't have time to dig into the implementation status of shared workers. What are the problems?

Why remove shared workers ?

@indolering
Implementation status of Shared Workers in under a second:

Google  - FLAWED
Apple   - REMOVED
Mozilla - CORRECT
Others  - WHATEVER

@GrosSacASac
Ask Apple why they removed Shared Workers.

@indolering thanks for the info. I use SharedWorker API because of performance goals and popular platform support. I target as many user platforms as possible, and will use or drop any API to achieve these goals.

@dinoluigivercotti Please explain "advertiser driven hack". Is there a problem with ads in Chrome that does not appear in MOZ? I target both platforms with the same SharedWorker scripts delivered to my clients.

With these SharedWorker scripts, the user experience and system throughput is improved by an order of magnitude across all stable OS versions (including mobile) of the Chrome and MOZ platforms. Chrome exhibits even more improvement than MOZ, not less. Why do you say MOZ is superior?

They don't talk.

@GrosSacASac IMO, Apple dropped Shared Workers because the Chromium implementation is curiously flawed, imo for ad revenue purposes, and Apple don't share. Opensource is free speech, and you are right: Apple don't talk either. They won't pull the Mozilla implementation since that would oblige them to contribute something, even if it is just attribution.

@indolering @dcerisano the problem is that in certain situations, the same Shared Worker API calls will behave differently on Chromium based browsers (80 freaking % of all browsers out there) than Mozilla based browsers (7 blessed %), with the latter being the expected behavior.

I am still trying to determine which part of the codebase is causing this, but I stated my opinion as to why it is happening. Apple and Microsoft decisions to deprecate (this GH issue) support that opinion.

If you don't see cross platform problems with your scripts, then you have nothing to worry about.

I am currently in (very one-way, but escalating) discussions with the parties concerned. Have not heard much worth mentioning from them yet.

I would prefer if people would resist to comment their opinions about why some browser vendor has done or not done something unless they work for that browser vendor. Speculation is not helpful. Unless this thread gets back on track about the issue at hand we will lock the thread.

cheers

@zcorpan Sorry about spamming your notification feed, I'll try to move discussion off-thread as quickly as possible : )

@dinoluigivercotti I've only done POC code and neither caniuse.com nor Chrome's platform status mention any issues. I've opened a ticket on caniuse's Github repo, would you mind commenting over there?

I'm happy to have the discussion here, to be clear. Don't worry about my notification feed. 🙂

@annevk originally invited people to speculate/opine as to whether the living HTML standard _should_ have a SharedWorker depcrecation warning.

@dinoluigivercotti you reported there are implementation inconsistencies in the Chrome API that caused some other API vendors to deprecate SharedWorkers. Your opinion as to underlying reasons is not relevant without detailing the inconsistencies, as @indolering, @GrosSacASac and I requested. Results before conclusions please.

@zcorpan This thread is a over year old and still no SharedWorker deprecation warnings from Google or MOZ. This is a fractured situation, where other powerful vendors have decided to drop support for a standard. They may have been premature. This thread should track any progress.

For my part, I will keep delivering SharedWorkers to my clients. They are an excellent performance solution with majority platform support.

Isn't it possible to actually get some flavor of "SharedWorker" by simply make usage of a WebWorker which would then use the BroadcastChannel API?

@dcerisano Mark as deprecated, it will either motivate everyone to either improve the SharedWorker implementation or enhance ServiceWorkers.

@zeropaper How would you decide which tab to store the SharedWorker in?

I'm locking this for now since we primarily need input from implementers. I certainly did not mean to invite speculation.

Closing this per https://github.com/whatwg/html/issues/2887#issuecomment-319844597. It seems there's some potential interest still from others and neither Chrome nor Firefox is inclined to remove.

Just wanted to followup with some thoughts: WebWorker, Shared WebWorker, and Service Worker are just different execution environments for the actor model – but without the niceties of a built-in API.

The Actor model is a natural fit for async-native modern JS: just define an interface via export and spawn a new worker. Instead, we are stuck hand-rolling an API, which prevents code sharing between projects.

_Something_ needs to be done to reboot *Workers, very few users are willing to maintain 3 different code paths, fight obscure bugs sans a proper debugging environment, and auditing port.channel and origin/function issues is a nightmare.

I've seen similar proposals in the past (spawn and frozen realms?) but perhaps *WebActors could be the way out of the current *WebWorker chicken-and-egg stalemate.

Argh, sorry @annevk I just reread your penultimate post :p I just reviewed the ticket and @zcorpan's comment encouraging discussion prompted me to post. I'll stop hijacking this thread.

We are using SharedWorker in big project. We have 1M+ uniq users every day.
SharedWorker+WebSocket save a lot of money for us.
ServiceWorker have no durable lifetime. We can't use it with websocket, cos ServiceWorker can shutdown in any moment.

@SowingSadness what is the project ? Are you using sharedworker to keep a persistent worker open across tabs ?
Have you tried to use simple worker + postmessage ? You can emulate shared worker that way. (at a great cost of efficiency)

I also hope that sharedworker stays in the html spec

@GrosSacASac Hi. online.sbis.ru is that project. You can't use postmessage for cross tab messaging cos you haven't tab reference.
We are using localstorage + websocket in one tab for browser without sharedworker support, but in this case you can lost a message.

It is true there is no way to get the all the tabs references under the same origin out of nowhere. That is why Window.postMessage() is still limited and shared worker required.

Service Workers are just request handlers (like a thread pool). They exist to serve requests to services (eg. a cloud service or remote database) and expire. This prevents the DOM thread from blocking during requests. The term 'Worker' only means that work is being done off the DOM thread - any patterns that might block the UI. There won't be a single monolithic "Über Worker" redesign, as has been suggested - that might sound good to a project manager, but it would be an antipattern. Rather, look for more worker patterns soon, eg. GL Workers (Vulkans!).

What is the alternative to Shared Worker if not all modern browsers are supporting it?

@playground

  • Design web app so that it does not require multiple tabs open
  • Share the work and the state on a separate server via HTTP for example
  • Define a master ui main thread + window.postmessage
  • Some things can be done with a service worker
  • replicate the work on each tab and use localstorage, indexdb and co to share state

@playground when people start complaining about poor webapp performance, browser-shaming will force Shared Workers to become universally supported.

@dcerisano shared worker is not about perfomance, it's about economy money in traffic and server infrastructure.

@grossacasac try to send messages from server to browser of 10 million users. All your suggestion not economy true

@SowingSadness

That is why browsers should support Shared Workers

@GrosSacASac my use case does not require multiple tabs open, however does require some heavy lifting in the web worker and also leveraging indexedDB. I was exploring ways that I can spread the workload amount multiple workers to improve processing time since all devices come with multiple cores these days. With window.postmessage, one can only pass around structured data, I need a way to stitch all results back together and it's been proving to be a difficult task. I think Shared workers would be an ideal solution in this case.

@SowingSadness, not everything is about money - that would be depressing.

The Shared Worker pattern is about UI responsiveness and unblocking the user experience in complex web applications - ie seamless browser performance.

Ironically, the reason some browsers do not support Shared Workers is that they are too cheap to pay for the required development, testing and maintenance. They obviously consider user experience to be external to their business models.

Shared worker is critical for a project we work on. Hope that Microsoft and Apple support it.

@newtack i think support will not be. In chrome a shared worker is buggy.

We used the shared worker for one websocket channel to browser in a domain. Today we have dropped support and migrate to a BroadcastMessage + logic in pages.

Thanks @SowingSadness.
Can you point me to a link with more info on BroadcaseMessage?
What benefits/downsides does this approach have, other than obviously being supported by all browsers?

@newtack sorry, i mean a Broadcast Channel.
We have to many clients with slow PC. And we have responsibility for our product. In Chrome are using the shared worker not available for us. In Firefox, debugging the shared worker is hard, Cos you can’t attached to JS and can’t watching network requests.
In result this technology to expencive and don't bring profit

@SowingSadness Got it and thanks for the answer.
When I looked at caniuse.com neither Safari nor Edge support it. Do you not support those browsers or do you have another solution for them?

@newtack we are using own polifill. It work around a localStorage. If your target mobile Safari too, you should forget about all technology of between tabs work. Cos the browser is big heap of bugs.

Was this page helpful?
0 / 5 - 0 ratings