graphql-js
graphql-js copied to clipboard
Performance issue with GraphQLError.js with sourcemaps enabled
This code lines https://github.com/graphql/graphql-js/blob/16009cbcb0109da03f2157a868817b886801095a/src/error/GraphQLError.js#L189-L196 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.
We hit this issue too without even trying to enable source maps
Is there something actionable here for this repo?
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