0

I want to turn off ZoneAwareError in Angular for the performance issue.

enter image description here enter image description here

I try to find a solution at the Documents, but I couldn't find it.

Are there other APIs to solve this problem?

egaoneko
  • 389
  • 1
  • 5
  • 24
  • Do you have evidences that ZoneAwareError is causing performance issues? Maybe it adds few lines of code for every Error, but we are still in the case of [micro-optimization](https://en.wiktionary.org/wiki/micro-optimization). By the way, you can try `zone.runOutsideAngular()` – Christian Vincenzo Traina Jul 29 '19 at 10:05
  • PS. In your example you're showing that the processor spends a lot of time inside a ZoneAwareError, but it doesn't say that using a plain Error it would be better! Errors (as much as Exceptions in other programming languages) are always expensive – Christian Vincenzo Traina Jul 29 '19 at 10:06
  • PS. (again): Are you using Errors and try/catch inside a loop? This is a known bad practice – Christian Vincenzo Traina Jul 29 '19 at 10:08
  • @CristianTraìna I just called Promise.reject that time. When I didn't catch, Chrome show `Uncaught (in promise) [object Object]: ` Error. – egaoneko Jul 29 '19 at 11:24
  • @CristianTraìna And it take 0.5ms per each process. – egaoneko Jul 29 '19 at 11:28
  • @CristianTraìna This processor is not in angular and it called and initialized before angular. – egaoneko Jul 29 '19 at 11:45

1 Answers1

0

I solved it by refactoring catch logic like under code.

As Is.

const promise = new Promise(() => {});
promise.catch(() => {});
promise.then(() => {});

To Be.

let promise = new Promise(() => {});
promise = promise.catch(() => {});
promise.then(() => {});
egaoneko
  • 389
  • 1
  • 5
  • 24