angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Feat: Run angular in web worker mode

Open k3nsei opened this issue 10 years ago • 65 comments

In current setup there is no possibility to bootstrap angular in web worker mode. Please add this killer functionality.

k3nsei avatar Sep 23 '16 09:09 k3nsei

Bump.

ShadowManu avatar Jul 27 '17 17:07 ShadowManu

@filipesilva For larger applications with heavy computations this is quite important. Otherwise the cli tool is more or less a no go. Agree with @bmayen that this should be bumped. Given the number of "thumbs up" across this post would it be worth reconsidering?

jt-helsinki avatar Jul 28 '17 21:07 jt-helsinki

FWIW, sorting issues by reaction shows this as the top 3 for both +1s and hearts. Definitely a strong community desire behind this!

bmayen avatar Jul 29 '17 17:07 bmayen

Hey all, I brought this up with the team today, and currently this is something we're interested in adding, but not something we have the time right now to both incorporate and properly validate that would work.

It would probably require a new entry point for the worker bootstrap and some codegen changes. I'm sorry to say that for now the recommended approach is to eject.

@maxime1992 posted about a very detailed guide: https://stackoverflow.com/questions/43276044/angular-cli-generated-app-with-web-workers/43276045

Have you tried it? Does it work in all cases? What are the caveats? This sort of information would be very valuable for the initial design of it. Having a clear path that starts at ejecting helps define what needs to change inside the CLI for non-ejected projects.

filipesilva avatar Aug 01 '17 17:08 filipesilva

Thanks @filipesilva. Unfortunately I don't have any detailed feedback to provide on the eject-based approach. Our project which needed WW was based on the AngularClass starter and we rolled our own solution there; based on that link but not using the CLI.

We had started work on a PR to integrate the above approach in the CLI, but according to https://github.com/angular/angular-cli/issues/5885#issuecomment-300446321, this would not have been the preferred approach, so we decided to abandon it and wait for the pending platform-server work to pave the way. But if a PR along these lines would be welcomed now, I could potentially revisit that WIP (depending on availability).

bmayen avatar Aug 01 '17 19:08 bmayen

@filipesilva @bmayen

One of the issues with the eject approach is that it is not possible to hash the bundle file names. It also seems that we need multiple config files for multiple environment builds which becomes a bit unwieldily. Admittedly, refactoring the config would solve this.

jt-helsinki avatar Aug 01 '17 21:08 jt-helsinki

@MurhafSousli I am right there with you, one of the few reasons I won't be making anything new with angular if I can help it. 😕

jakeNiemiec avatar Sep 08 '17 14:09 jakeNiemiec

I've been waiting for that too :sweat_smile:

image

It'd be nice to see the priority bumping at least from 3 to 2 ;)

maxime1992 avatar Sep 12 '17 13:09 maxime1992

I have this suspicion for a while, that the reason that we seen no progress on this is because the angular team is moving in another direction or waiting for some other technology that would make the current webwork implementation obsolet.

I have no proof of this, but I think the answer to the question about what new technology the different framework looks forward to the most during the "Chrome Dev Summit 2017" is telling. Basically everyone agrees that the DOMChangeList would be great.

Please see the answer from the Angular representative on the panel here: http://www.youtube.com/watch?v=q5HDhQtpDRU&t=3m30s

And more about the DOMChangeList here: https://github.com/whatwg/dom/issues/270

jhertz123 avatar Oct 29 '17 09:10 jhertz123

How would this make current implementation obsolete? Wouldn't current implementation just batch calls to the UI thread via DOMChangeList? There would be changes required to DomRenderer, sure, but I don't see this completely deprecating the current Webworkers implementation. More of an optimization, no?

In terms of how this affects CLI, I don't see it either. The issue with missing CLI support is less to do with the specific Angular implementation AFAIK.

bmayen avatar Oct 29 '17 12:10 bmayen

Sorry I were a bit unclear in my comment. I don't mean it is obsolet, that were only my suspicion. What I tried to say is things are happening in this space an I think one of the reasons we are not seeing any progress on this is because things are still a bit up in the air. But this is of course just speculations.

jhertz123 avatar Oct 30 '17 08:10 jhertz123

I want to share my experience with you.

I made a enterprise application with Angular V4 and when I render a couple hundred records on screen it's incredible more slower than in AngularJs. I'm sure I haven't done all the performance work to get it working smooth. But in the development stage of the app it works at light speed, I see this slow app now that the volume of records growth and had the chance to experience the (now) normal UI block all the time. In the other hand my old AngularJs app has the same info and maintains its usual speed, not so fast, but no the slowest.

I really don't know if this change could improve the UI speed, but I know that in my case, when a huge payload of information is handled by Angular, all those filters, maps, and other transform operations feels right to be done in a separate thread.

It's just an opinion, I would really like to see this come through.

Thanks for the great work!!!

MartinFreire avatar Nov 13 '17 18:11 MartinFreire

@IgorMinar @mhevery I heard from @hansl you had looked into this topic, could you give an answer here please?

filipesilva avatar Nov 14 '17 10:11 filipesilva

Can you get a rough estimate for the cli integration and we can discuss it then during the next planning session.

On Tue, Nov 14, 2017, 11:32 AM Filipe Silva [email protected] wrote:

@IgorMinar https://github.com/igorminar @mhevery https://github.com/mhevery I heard from @hansl https://github.com/hansl you had looked into using Webworkers in Angular, could you give an answer here please?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/2305#issuecomment-344215407, or mute the thread https://github.com/notifications/unsubscribe-auth/AANM6JF4RXYoXWo97j2sar8nCtyKuvVtks5s2WxYgaJpZM4KEyA1 .

IgorMinar avatar Nov 14 '17 10:11 IgorMinar

@IgorMinar and @filipesilva can you please also discuss how Material 5 could be integrated when running Angular app in Web worker mode?

Ref: https://github.com/angular/material2/issues/1406#issuecomment-251141980

Current plan is to support it once the WebWorker support in Angular core improves. In particular, Material needs custom renderers (to deal with marshalling between UI and worker threads).

However, it's not yet clear whether using web workers at all would actually be an improvement for the types on lower-level ui components that material offers; pretty much all of the logic in the components deals with changing the rendered DOM in some way. Given that, it may end up being faster for material to continue running on the UI thread even when web-worker support is out of experimental.

naveedahmed1 avatar Nov 14 '17 11:11 naveedahmed1

It takes no long until you face a situation in your app where it could be great to have the Web worker mode feature. I've been using Angular + Material for about a year and right now one of my projects needs a dashboard. Lots of json data could potentially arrive from the backend to be plotted on the screen (depends on how complex each end user will setup his particular dashboards - there's no limit on the number of charts he can choose to see in each of his dashboards) and I'm really worried about how this feature will behave without web workers. It doesn't depends just on Angular, but also on chartjs - apparently both of them need hacks to run in web worker mode.

Ideally I'd show a panel to the user and after that I'd go to the server to get each chart data - and the charts, one by one, would become visible in the panel. But if I do that, it's likely each chart won't be updated in the screen smoothly. So I changed my mind and I think I'll get all of the data from the server before showing the user anything. And I hope it works.

I think I'll have some trouble with ux sooner or later.

julianobrasil avatar Nov 15 '17 12:11 julianobrasil

I've created a web-worker.service to offload high CPU tasks similar to the example/demo posted above and I am now a huge fan as well. This would be a great addition to the cli!

Tyler-V avatar Nov 29 '17 04:11 Tyler-V

Anyone have any update to date webpack configs with Angular 5 for this? My web workers stopped working after migrating from 4 to 5.

evanjmg avatar Jan 22 '18 16:01 evanjmg

I am looking for adding Web worker with Angular CLI but didn't found nay solution yet. Waiting for this !!!

dipaktelangre avatar Feb 27 '18 07:02 dipaktelangre

If you want to use Web Workers in Angular, just use the Web Worker. See angular2-web-worker$web-worker.ts for an implementation. Is plain simple JS at the end.

This is about run the entire Angular application inside a Web Worker.

michaeljota avatar Mar 16 '18 13:03 michaeljota