Significant performance regression with C++ package_json_reader cacheΒ #58126
Copy link
Copy link
Closed
Labels
c++Issues and PRs that require attention from people who are familiar with C++.Issues and PRs that require attention from people who are familiar with C++.moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.
Description
Version
21.5.0
Platform
Darwin COMP-F2RFYQPYC7 24.4.0 Darwin Kernel Version 24.4.0: Fri Apr 11 18:32:50 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6041 arm64 arm Darwin
Subsystem
module
What steps will reproduce the bug?
The bug was originally reported as performance regression in the aws-cdk-lib when using Node.js v22 instead of v20. The regression seems to surface stronger in combination with dd-trace, which instruments the library code.
When I ran a flamegraph on the below example, at least 80% of time is spend in Node.js package_json_reader (image)
npm i dd-trace aws-cdk-lib constructs
nvm i 21.4.0
time node test.js
# About 500 ms on my device
nvm i 21.5.0
time node test.js
# About 4500 ms on my devicerequire('dd-trace').init();
const cdk = require('aws-cdk-lib');
const app = new cdk.App();
for (let i = 0; i < 1000; i++) { // simulate a large CDK app
new cdk.Stack(app, `DdTraceStack${i}`);
}I do not have the time to look into it deeper, so I also can't post any reproducible code without external code.
It does seem to be related to this PR: #50322
CC @anonrig
See also aws/aws-cdk#33576, DataDog/dd-trace-js#5360, aws/aws-cdk#34112
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
To have about the same runtime as v21.4.0
What do you see instead?
The runtime increases by a factor of 9x
Additional information
No response
Reacted by Momo Kornher and Nuno
Metadata
Metadata
Assignees
Labels
c++Issues and PRs that require attention from people who are familiar with C++.Issues and PRs that require attention from people who are familiar with C++.moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.
Activity
anonrig commentedon May 12, 2025
I'm starting to look into this... It takes 15 seconds on my machine...
anonrig commentedon May 12, 2025
It seems GetPackageJSON is called multiple times with same/similar parameters.
BridgeAR commentedon May 19, 2025
@anonrig yes, the original method cached this and did not have a high overhead. Now it always does the work again, if I am not mistaken.
BridgeAR commentedon May 19, 2025
It seems the new code removed the cache, if I read it correct.
anonrig commentedon May 19, 2025
It has cache. There is a std::unordered_map that stores the cache. I assume there is a bug somewhere that invalidates the cache.