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

Performance issue with GraphQLError.js with sourcemaps enabled #2800

Open
istarkov opened this issue Sep 15, 2020 · 3 comments
Open

Performance issue with GraphQLError.js with sourcemaps enabled #2800

istarkov opened this issue Sep 15, 2020 · 3 comments

Comments

@istarkov
Copy link

istarkov commented Sep 15, 2020

This code lines

if (originalError?.stack) {
Object.defineProperty(this, 'stack', {
value: originalError.stack,
writable: true,
configurable: true,
});
return;
}
cause serious performance degradation in case of node used with sourcemaps.
For example dataloader fail on reading list of N nodes can cause N*100ms delay.

Explanation:
Modern nodejs has sourcemaps support via --enable-source-maps flag.
In current nodejs access to error.stack object is lazy, so until you read it where are no additional logic called to prepare stack traces i.e. Error.prepareStackTrace

With sourcemaps enabled node resolution algorithm for trace is not chip and on big projects costs like 100ms to build trace using sourcemaps. (see nodejs prepare stack trace)

For example on reading list of 30 items in case of dataloader fails we have 3000ms delay because of reading stack at that lines.

I found that for unknown reason Object.defineProperty cause prepareStackTrace to be called. But setting this.stack = null; before solves the issue.

Have no idea why.

@ex3ndr
Copy link

ex3ndr commented May 13, 2021

We hit this issue too without even trying to enable source maps

@yaacovCR
Copy link
Contributor

Is there something actionable here for this repo?

@NShahri
Copy link

NShahri commented Jan 10, 2024

The same thing happened to us on node18 on the local/dev machine and production console.

We switched to node20 and the performance issue was resolved on the local/dev machine but it still has the same issue on production. we decided to remove the --enable-source-maps node option for now.

We are using:

  • esbuild
  • serverless (AWS lambda)
  • typescript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants