Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

ZoneAwareError is 15-20x slower than native, should lazy-evaluate "stack" #975

@mleibman

Description

@mleibman

Getting a stack trace can be an expensive operation, and both Firefox and Chrome/V8 (haven't checked IE/Edge) optimize it by formatting the unstructured stack trace of an error on demand, the first time the stack property is accessed (https://github.com/v8/v8/wiki/Stack-Trace-API#customizing-stack-traces).

When building instrumentation tooling, I use this to minimize the overhead of capturing the stack trace using new Error() and then evaluate its stack property if and when needed. Unfortunately, ZoneAwareError does the trace evaluation and formatting in its constructor, so it ends up a lot slower, both from invoking the native error's formatting, and Zone.js's own overhead. I have also noticed it resulting in increased memory pressure, leading to more frequent GC pauses:

zoneawareerror

(The first half is running new NativeError(), the second is running new Error().)

Benchmark demonstrating the issue - https://jsperf.com/zoneawareerror.
Note that this runs the benchmark with an unrealistically shallow call stack. The real life impact in a complex application is likely to be more pronounced.

Is it possible to make it evaluate and rewrite the stack on demand?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions