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

CLI causes bad application performance in Chrome

Open junjunruan opened this issue 9 years ago • 5 comments

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.4.1 node: 6.11.3 os: darwin x64 Chrome: 60.0.3112.113

Repro steps.

I had a simple angular app uses a third party library called cornerstone to do window leveling on image.

Two repos were created to implement this feature: one with CLI (see github repo: https://github.com/junjunruan/ng4-cli), another one with Systemjs (see github repo: https://github.com/junjunruan/ng4-systemjs). They have a big difference in the time cost on a for loop from cornerstone library in Chrome. Steps of how to run the application is included in each repo's README file.

CLI Time Cost

When use CLI to run the app, the performance is very bad in Chrome. I noticed that a for loop from cornerstoneWebImageLoader.orig.js file takes very long time. Here is the for loop code looks like:

var startLoopTime = new Date().getTime()/1000;
for(var i=0; i < numPixels; i++) {
      storedPixelData[storedPixelDataIndex++] = imageDataData[imageDataIndex++];
      storedPixelData[storedPixelDataIndex++] = imageDataData[imageDataIndex++];
      storedPixelData[storedPixelDataIndex++] = imageDataData[imageDataIndex++];
      storedPixelData[storedPixelDataIndex++] = 255; // alpha
      imageDataIndex++;
}
console.log('For loop time:' + (new Date().getTime()/1000 - startLoopTime));

Here is the time cost in each click of "window leveling" button (each click calls for loop once):

In takes more time on for loop only after the second click.

Systemjs Time Cost

When switch back to Systemjs as module loader, the application's performance is pretty good. Here is a screenshot of time cost of the same for loop.

The log given by the failure.

Desired functionality.

Hopefully CLI can give us the same performance as using Systemjs module loader in both development and production, and in all major browsers.

Mention any other details that might be useful.

junjunruan avatar Sep 12 '17 04:09 junjunruan

hi @junjunruan, thanks for the well-written issue and repros. Angular / the CLI don't really handle Webpack/SystemJS any differently, in the sense that Typescript outputs the same code to be fed into either bundler.

My guess would be that something about how Webpack/System bundle affects how an engine like Chrome parses / optimizes / inlines specific bits of code. I would be very, very curious to know if you see the same behavior if you were to build a vanilla (non-Angular) application, using cornerstone, and bundled the same way. If you can reproduce the issue there, then the problem likely lies with Webpack itself, and you should file an issue over there. If not, then possibly its an issue with CLI.

If you can get a repro w/o Angular, I can certainly share it with the appropriate team at Webpack or here at Google.

robwormald avatar Sep 22 '17 19:09 robwormald

Assigning this to @robwormald because we (the CLI team) like him.

hansl avatar Sep 25 '17 17:09 hansl

@robwormald I created two non-Angular repos, one is using systemjs (see repo: https://github.com/junjunruan/non-angular-systemjs), another one is using webpack(see repo: https://github.com/junjunruan/non-angular-webpack). Unfortunately, both of them had bad performance, almost the same time cost as from the Angular+CLI example.

junjunruan avatar Sep 26 '17 14:09 junjunruan

Thanks for reporting this issue. This issue was originally reported a long time ago and since then we've had many releases, one of which might have addressed this problem. Please update to the most recent Angular CLI version.

If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

filipesilva avatar Oct 01 '19 16:10 filipesilva

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.