Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ember/V8: Slow EmberError constructor #15516

Closed
schuay opened this issue Jul 17, 2017 · 15 comments
Closed

Ember/V8: Slow EmberError constructor #15516

schuay opened this issue Jul 17, 2017 · 15 comments

Comments

@schuay
Copy link

schuay commented Jul 17, 2017

I heard through the grapevine that error handling is very slow when using current V8 versions (e.g. 6.0).

Looking at the EmberError constructor [0], the main offender is probably the call to Error.captureStackTrace. captureStackTrace used to format the stack trace lazily on access to the stack property (like builtin error objects), but since about a year it formats traces eagerly. That could be fairly expensive, and would explain a sudden slowdown in error handling code. We're looking into re-enabling lazy formatting in Error.captureStackTrace [1] soon.

I also noticed that each call to the EmberError constructor collects the stack trace three times:

  1. In the call to super()
  2. In the explicit Error.call(this, message)
  3. In Error.captureStackTrace.

Maybe it'd be possible to avoid some of this useless work? In current V8 versions, it should be enough to just call super(message) - this will also filter to relevant frames (as Error.captureStackTrace does).

[0]

Error.captureStackTrace(this, EmberError);

[1] https://crbug.com/v8/5962

cc @hashseed, @bmeurer, @stefanpenner

@stefanpenner
Copy link
Member

@schuay I believe our usage of Error.captureStackTrace are purely for cosmetic reasons. I'll just remove it.

stefanpenner added a commit that referenced this issue Jul 17, 2017
We only do this for stack cosmetic reasons, it really just removes 1 or so frames, but apparently more recently at a hefty cost:

context: #15516
@stefanpenner
Copy link
Member

stefanpenner commented Jul 17, 2017

@stefanpenner stefanpenner self-assigned this Jul 17, 2017
@stefanpenner
Copy link
Member

In the call to super()
In the explicit Error.call(this, message)

is kinda funny bit-rot. Time to clean that up.

stefanpenner added a commit that referenced this issue Jul 17, 2017
We only do this for stack cosmetic reasons, it really just removes 1 or so frames, but apparently more recently at a hefty cost:

context: #15516
stefanpenner added a commit that referenced this issue Jul 17, 2017
We only do this for stack cosmetic reasons, it really just removes 1 or so frames, but apparently more recently at a hefty cost:

context: #15516
stefanpenner added a commit that referenced this issue Jul 17, 2017
As pointed out by @schuay #15516 our error constructor essentially calls super twice. The reasons seems to have been an error in ExtendableBuiltin constructor, which did not return its `apply` call. I can’t seem to find the issue ExtendBuiltin is working around. I suspect we can simply remove it
@stefanpenner
Copy link
Member

We also do stack trace stuff herE: https://github.com/emberjs/ember.js/blob/master/packages/ember-debug/lib/deprecate.js#L81-L118

When we provide deprecations. These get hit quite abit, I wonder if we should log a deprecation sans stack, but provide via console message how to enable stacks...

Thoughts @rwjblue ?

stefanpenner added a commit that referenced this issue Jul 17, 2017
As pointed out by @schuay #15516 our error constructor essentially calls super twice. The reasons seems to have been an error in ExtendableBuiltin constructor, which did not return its `apply` call. I can’t seem to find the issue ExtendBuiltin is working around. I suspect we can simply remove it
stefanpenner added a commit that referenced this issue Jul 17, 2017
As pointed out by @schuay #15516 our error constructor essentially calls super twice. The reasons seems to have been an error in ExtendableBuiltin constructor, which did not return its `apply` call. I can’t seem to find the issue ExtendBuiltin is working around. I suspect we can simply remove it
locks pushed a commit that referenced this issue Jul 17, 2017
We only do this for stack cosmetic reasons, it really just removes 1 or so frames, but apparently more recently at a hefty cost:

context: #15516
@schuay
Copy link
Author

schuay commented Jul 18, 2017

I'm a bit confused by

. The 'Chrome' branch seems like dead code, at least on current versions. There's no 'arguments' property in error objects.

It might also be easier for you to use Error.prepareStackTrace (V8 only) to extract relevant info rather than expensive RegExp.p.replace calls. See https://github.com/v8/v8/wiki/Stack-Trace-API.

@schuay
Copy link
Author

schuay commented Jul 18, 2017

By the way, Error.captureStackTrace now formats lazily again: https://chromium-review.googlesource.com/c/574530/

@stefanpenner
Copy link
Member

I'm a bit confused by

. The 'Chrome' branch seems like dead code, at least on current versions. There's no 'arguments' property in error objects.

Ya that code does look funky. I suspect needs some TLC, looking now

@stefanpenner
Copy link
Member

stefanpenner commented Jul 18, 2017

When we provide deprecations. These get hit quite abit, I wonder if we should log a deprecation sans stack, but provide via console message how to enable stacks...

LIkely just via the ENV.LOG_STACKTRACE_ON_DEPRECATION

@stefanpenner
Copy link
Member

@schuay Error.prepareStackTrace doesn't seem available..

@stefanpenner
Copy link
Member

@schuay Error.prepareStackTrace doesn't seem available..

Ah this method, we must implement. I forgot about it :P

@stefanpenner
Copy link
Member

It might also be easier for you to use Error.prepareStackTrace (V8 only) to extract relevant info rather than expensive RegExp.p.replace calls. See https://github.com/v8/v8/wiki/Stack-Trace-API.

thoughts on #15524 ?

@pixelhandler
Copy link
Contributor

@schuay @stefanpenner is this still an issue, perhaps we should close, what do you think?

@schuay
Copy link
Author

schuay commented Oct 8, 2018

I don't know what the current status is - have all fixes landed?

@stefanpenner
Copy link
Member

I believe they have not landed, there were some strange test failures and I simply didn't have the time to debug them.

@locks
Copy link
Contributor

locks commented May 30, 2019

I'm closing due to inactivity. If this is still relevant, please reopen!

@locks locks closed this as completed May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants