-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Description
Version
v22.19.0
Platform
Darwin ZG-F3FWLW4DJJ 24.6.0 Darwin Kernel Version 24.6.0: Mon Jul 14 11:28:30 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6030 arm64
Subsystem
No response
What steps will reproduce the bug?
Node 22.19.0 uses significantly more heap memory than 22.18.0. I think it's because of this change, which introduces a cache for package.json
metadata. Some packages are structured in such a way that this cache ends up quite large. The reproduction provided here uses date-fns
, which exhibits this clearly.
To reproduce, compare heap snapshots for a script like this:
{
"dependencies": {
"date-fns": "^4.1.0"
}
}
const http = require('node:http');
const {
formatISO,
} = require('date-fns');
const server = http.createServer((req, res) => {
if (req.method === 'GET') {
res.writeHead(200);
res.write(`${formatISO(new Date())}\n`);
res.end();
}
});
server.listen(3000);
In my testing, the total heap size for this script on 22.18 is ~7.2 MB, whereas on 22.19 it's ~28.9 MB. This was originally detected in a medium size application where an upgrade to 22.19 ballooned heap usage by more than 50 MB. Inspecting a heap snapshot shows that much of this increase is accounted for by objects retained by nearestParentPackageJSONCache
How often does it reproduce? Is there a required condition?
It reproduces consistently on 22.19.0
What is the expected behavior? Why is that the expected behavior?
I would not expect such a significant increase in heap usage
What do you see instead?
A significant increase in heap usage
Additional information
A zip containing heap snapshots for the reproduction script is attached