Performance Regressions with Node24 and metadata collection
Describe the bug
This was opened as a requested here: https://github.com/aws/aws-cdk/issues/36078#issuecomment-3738397539
We saw massive performance regressions with these warnings (ref #36078) and switching from Node 22 to Node 24.
We have a monorepo, and we currently have around ~100 of these warnings. We are on version 2.224.0. The Node upgrade caused massive slowdowns in cdk synth and cdk deploy. On Node 24.1.1: With "@aws-cdk/core:enableAdditionalMetadataCollection": false cdk synth -v -v --strict 43.73s user 13.47s system 65% cpu 1:27.11 total With "@aws-cdk/core:enableAdditionalMetadataCollection": true, cdk synth -v -v --strict 122.27s user 13.58s system 83% cpu 2:43.33 total
We also saw slowdowns on cases without synthesizing (cdk deploy --app cdk.out), going from 4s to 30s. I don't know certain where is this coming from (IO?), the debug logs are not very useful here.
As a workaround I will keep "@aws-cdk/core:enableAdditionalMetadataCollection" set to false.
Regression Issue
- [ ] Select this option if this issue appears to be a regression.
Last Known Working CDK Library Version
No response
Expected Behavior
No massive performance loss on Node24, while having >100 stack warnings
Current Behavior
The Node upgrade caused massive slowdowns in cdk synth and cdk deploy. On Node 24.1.1: With "@aws-cdk/core:enableAdditionalMetadataCollection": false cdk synth -v -v --strict 43.73s user 13.47s system 65% cpu 1:27.11 total With "@aws-cdk/core:enableAdditionalMetadataCollection": true, cdk synth -v -v --strict 122.27s user 13.58s system 83% cpu 2:43.33 total
Reproduction Steps
Have a repo with >100 warning, use node24.
Possible Solution
No response
Additional Information/Context
No response
AWS CDK Library version (aws-cdk-lib)
2.224.0
AWS CDK CLI version
?
Node.js Version
24
OS
MacOS
Language
TypeScript
Language Version
5.8.3
Other information
No response
checking in. Looking into this issue.
Hi @henrys-funke,
Thank you for reporting this performance issue with detailed metrics. We've been investigating based on your report and the context from #36078.
We reproduced the warning generation using 100 IAM Roles with fromAwsManagedPolicyName() on Node 24.9.0 and CDK 2.224.0:
| Metadata Collection | Synth Time |
|---|---|
| OFF | 97ms |
| ON | 231ms |
| Overhead | +134ms (+138%) |
While we confirmed the metadata collection does add overhead (as @mrgrain suggested), our +134ms is significantly less than your reported +76s overhead. This suggests your monorepo has additional scale factors we're not capturing.
To help us understand the gap, could you clarify:
-
Total construct count - Beyond the ~100 warnings, approximately how many total constructs/resources are in your monorepo? (Lambda functions, roles, etc.)
-
Number of stacks - How many stacks are being synthesized?
-
Node 22 baseline - What were the synth times on Node 22 with metadata collection ON? This would help isolate whether Node 24 specifically is the issue.
-
The deploy slowdown - The
cdk deploy --app cdk.outgoing from 4s→30s is puzzling since it skips synthesis. Could you run with--debugto see where time is spent? -
Profiling - If possible, running
node --cpu-prof $(which cdk) synthwould help pinpoint the exact bottleneck.
In the meantime, the workaround is:
{
"context": {
"@aws-cdk/core:enableAdditionalMetadataCollection": false
}
}
With another large scale test, we were able to reproduce significant overhead by testing with deeply nested L3 constructs (Lambda + API Gateway + DynamoDB per logical unit):
| Logical Units | Stacks | Metadata OFF | Metadata ON | Overhead |
|---|---|---|---|---|
| 100 | 10×10 | 1.1s | 4.8s | +3.6s (+318%) |
| 400 | 20×20 | 4.0s | 18.8s | +14.9s (+376%) |
| 900 | 30×30 | 9.0s | 42.3s | +33.3s (+369%) |
At 900 logical units we see +33s overhead, which approaches your reported +76s. The overhead scales with construct nesting depth because redactTelemetryDataHelper() recursively traverses all props including child constructs.
Here's the benchmark code:
const cdk = require('aws-cdk-lib');
const lambda = require('aws-cdk-lib/aws-lambda');
const apigateway = require('aws-cdk-lib/aws-apigateway');
const dynamodb = require('aws-cdk-lib/aws-dynamodb');
const NUM_STACKS = parseInt(process.env.NUM_STACKS || '10');
const APIS_PER_STACK = parseInt(process.env.APIS || '10');
const METADATA = process.env.METADATA !== 'false';
console.log(`Stacks: ${NUM_STACKS}, APIs/Stack: ${APIS_PER_STACK}, Total: ${NUM_STACKS * APIS_PER_STACK}, Metadata: ${METADATA}`);
const start = Date.now();
const app = new cdk.App({
context: { '@aws-cdk/core:enableAdditionalMetadataCollection': METADATA }
});
for (let s = 0; s < NUM_STACKS; s++) {
const stack = new cdk.Stack(app, `TestStack${s}`);
for (let i = 0; i < APIS_PER_STACK; i++) {
// Lambda (creates Role, Policy, Function)
const fn = new lambda.Function(stack, `Fn${i}`, {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'index.handler',
code: lambda.Code.fromInline('exports.handler = () => {}'),
environment: { TABLE: `table-${i}`, STAGE: 'prod', REGION: 'us-east-1' },
timeout: cdk.Duration.seconds(30),
memorySize: 256,
});
// API Gateway (creates RestApi, Deployment, Stage, Resource, Method, etc)
new apigateway.LambdaRestApi(stack, `Api${i}`, {
handler: fn,
proxy: true,
deployOptions: { stageName: 'prod', throttlingRateLimit: 100 },
});
// DynamoDB Table
new dynamodb.Table(stack, `Table${i}`, {
partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
sortKey: { name: 'sk', type: dynamodb.AttributeType.STRING },
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
});
}
}
console.log(`Construct creation: ${Date.now() - start}ms`);
const synthStart = Date.now();
app.synth();
console.log(`Synth: ${Date.now() - synthStart}ms`);
console.log(`Total: ${Date.now() - start}ms`);
Run commands:
# Metadata OFF
NUM_STACKS=30 APIS=30 METADATA=false node isolated-test.js
# Metadata ON
NUM_STACKS=30 APIS=30 METADATA=true node isolated-test.js
Another test with
| Test | Synth Time | Overhead |
|---|---|---|
| Node 22 - Metadata OFF | 3.3s | baseline |
| Node 22 - Metadata ON | 4.9s | +1.6s (+50%) |
| Node 24 - Metadata OFF | 9.2s | +6.0s (+185%) |
| Node 24 - Metadata ON | 42.8s | +39.5s (+1200%) |
- Metadata collection on Node 22: +50% overhead
- Metadata collection on Node 24: +365% overhead (from 9.2s to 42.8s)
Node 24 massively amplifies the metadata collection overhead. I think this explains the user's report!
PoC
const cdk = require('aws-cdk-lib');
const lambda = require('aws-cdk-lib/aws-lambda');
const apigateway = require('aws-cdk-lib/aws-apigateway');
const dynamodb = require('aws-cdk-lib/aws-dynamodb');
const NUM_STACKS = parseInt(process.env.NUM_STACKS || '10');
const APIS_PER_STACK = parseInt(process.env.APIS || '10');
const METADATA = process.env.METADATA !== 'false';
console.log(`Stacks: ${NUM_STACKS}, APIs/Stack: ${APIS_PER_STACK}, Total: ${NUM_STACKS * APIS_PER_STACK}, Metadata: ${METADATA}`);
const start = Date.now();
const app = new cdk.App({
outdir: 'cdk.out',
context: { '@aws-cdk/core:enableAdditionalMetadataCollection': METADATA }
});
for (let s = 0; s < NUM_STACKS; s++) {
const stack = new cdk.Stack(app, `TestStack${s}`);
for (let i = 0; i < APIS_PER_STACK; i++) {
const fn = new lambda.Function(stack, `Fn${i}`, {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'index.handler',
code: lambda.Code.fromInline('exports.handler = () => {}'),
environment: { TABLE: `table-${i}`, STAGE: 'prod', REGION: 'us-east-1' },
timeout: cdk.Duration.seconds(30),
memorySize: 256,
});
new apigateway.LambdaRestApi(stack, `Api${i}`, {
handler: fn,
proxy: true,
deployOptions: { stageName: 'prod', throttlingRateLimit: 100 },
});
new dynamodb.Table(stack, `Table${i}`, {
partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
sortKey: { name: 'sk', type: dynamodb.AttributeType.STRING },
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
});
}
}
console.log(`Construct creation: ${Date.now() - start}ms`);
const synthStart = Date.now();
app.synth();
console.log(`Synth: ${Date.now() - synthStart}ms`);
console.log(`Total: ${Date.now() - start}ms`);
Run commands:
# Node 22 - Metadata OFF
nvm use 22 && NUM_STACKS=30 APIS=30 METADATA=false node isolated-test.js
# Node 22 - Metadata ON
nvm use 22 && NUM_STACKS=30 APIS=30 METADATA=true node isolated-test.js
# Node 24 - Metadata OFF
nvm use 24 && NUM_STACKS=30 APIS=30 METADATA=false node isolated-test.js
# Node 24 - Metadata ON
nvm use 24 && NUM_STACKS=30 APIS=30 METADATA=true node isolated-test.js
Log
cd /tmp/cdk-perf-test && source ~/.nvm/nvm.sh
echo "=== Node 22 - Metadata OFF ==="
nvm use 22 2>/dev/null
rm -rf cdk.out && NUM_STACKS=30 APIS=30 METADATA=false node isolated-test.js 2>/dev/null
echo ""
echo "=== Node 22 - Metadata ON ==="
rm -rf cdk.out && NUM_STACKS=30 APIS=30 METADATA=true node isolated-test.js 2>/dev/null
echo ""
echo "=== Node 24 - Metadata OFF ==="
nvm use 24 2>/dev/null
rm -rf cdk.out && NUM_STACKS=30 APIS=30 METADATA=false node isolated-test.js 2>/dev/null
echo ""
echo "=== Node 24 - Metadata ON ==="
rm -rf cdk.out && NUM_STACKS=30 APIS=30 METADATA=true node isolated-test.js 2>/dev/null (using tool: shell)
Purpose: Run all 4 test scenarios and show output
=== Node 22 - Metadata OFF ===
Now using node v22.21.1 (npm v10.9.4)
Stacks: 30, APIs/Stack: 30, Total: 900, Metadata: false
Construct creation: 419ms
Synth: 2774ms
Total: 3194ms
=== Node 22 - Metadata ON ===
Stacks: 30, APIs/Stack: 30, Total: 900, Metadata: true
Construct creation: 492ms
Synth: 4450ms
Total: 4942ms
=== Node 24 - Metadata OFF ===
Now using node v24.9.0 (npm v11.6.0)
Stacks: 30, APIs/Stack: 30, Total: 900, Metadata: false
Construct creation: 323ms
Synth: 8891ms
Total: 9214ms
=== Node 24 - Metadata ON ===
Stacks: 30, APIs/Stack: 30, Total: 900, Metadata: true
Construct creation: 434ms
Synth: 41971ms
Total: 42406ms
- Completed in 61.522s
> === Node 22 - Metadata OFF ===
Stacks: 30, APIs/Stack: 30, Total: 900, Metadata: false
Construct creation: 419ms
Synth: 2774ms
Total: 3194ms
=== Node 22 - Metadata ON ===
Stacks: 30, APIs/Stack: 30, Total: 900, Metadata: true
Construct creation: 492ms
Synth: 4450ms
Total: 4942ms
=== Node 24.12.0 - Metadata OFF ===
Stacks: 30, APIs/Stack: 30, Total: 900, Metadata: false
Construct creation: 364ms
Synth: 8744ms
Total: 9109ms
=== Node 24.12.0 - Metadata ON ===
Stacks: 30, APIs/Stack: 30, Total: 900, Metadata: true
Construct creation: 453ms
Synth: 41933ms
Total: 42386ms
Summary table:
| Scenario | Total | vs Node 22 OFF |
|----------|-------|----------------|
| Node 22.21.1 - Metadata OFF | 3.2s | baseline |
| Node 22.21.1 - Metadata ON | 4.9s | +1.7s (+53%) |
| Node 24.12.0 - Metadata OFF | 9.1s | +5.9s (+184%) |
| Node 24.12.0 - Metadata ON | 42.4s | +39.2s (+1225%) |
Key insights:
- Node 24 alone (metadata OFF) is ~3x slower than Node 22
- Metadata collection on Node 24 adds another +33s (from 9.1s → 42.4s)
- The combination creates a ~13x slowdown vs Node 22 baseline
Hi @henrys-funke,
Thank you for reporting this performance issue with detailed metrics. We've been investigating based on your report and the context from #36078.
We reproduced the warning generation using 100 IAM Roles with
fromAwsManagedPolicyName()on Node 24.9.0 and CDK 2.224.0: Metadata Collection Synth Time OFF 97ms ON 231ms Overhead +134ms (+138%)While we confirmed the metadata collection does add overhead (as @mrgrain suggested), our +134ms is significantly less than your reported +76s overhead. This suggests your monorepo has additional scale factors we're not capturing.
To help us understand the gap, could you clarify:
1. **Total construct count** - Beyond the ~100 warnings, approximately how many total constructs/resources are in your monorepo? (Lambda functions, roles, etc.) 2. **Number of stacks** - How many stacks are being synthesized? 3. **Node 22 baseline** - What were the synth times on Node 22 with metadata collection ON? This would help isolate whether Node 24 specifically is the issue. 4. **The deploy slowdown** - The `cdk deploy --app cdk.out` going from 4s→30s is puzzling since it skips synthesis. Could you run with `--debug` to see where time is spent? 5. **Profiling** - If possible, running `node --cpu-prof $(which cdk) synth` would help pinpoint the exact bottleneck.In the meantime, the workaround is:
{ "context": { "@aws-cdk/core:enableAdditionalMetadataCollection": false } }
I see that you already found a pretty good regression test case, I will still try to answer your questions to give context to the initial report.
- Total construct count
Counting with
const constructs = app.node.findAll().filter(
(c): c is Construct => c instanceof Construct
);
console.log(`Total constructs: ${constructs.length}`);
I get
Total constructs: 34776
-
Number of stacks 281
-
Node 22 baseline With Metadata ON, on Node 22
rm -rf cdk.out && time cdk synth -v && echo "on":cdk synth -v 126.35s user 19.12s system 71% cpu 3:24.73 total
With Metadata OFF, on Node22:
rm -rf cdk.out && time cdk synth -v && echo "off":
cdk synth -v 55.42s user 19.67s system 56% cpu 2:13.88 total
So it's +71sec for Node22. I could not reproduce the numbers from the initial report, but I can confirm the metadata slowdown.
- The deploy slowdown
I think you already found that with the telemetry helper, the debug log is not useful here. Snippet:
cdk deploy --app cdk.out -v --debug project-dev-app-webview-0-stack -e
[10:47:01] Unable to determine the default AWS account (CredentialsProviderError): Could not load credentials from any providers
[10:47:01] --app points to a cloud assembly, so we bypass synth
[Warning at /project-dev-app-webview-0-stack/Custom::CDKBucketDeployment8693BB64968944B69AAFB0CC9EB8756C4096MiB/ServiceRole] Failed to add construct metadata for node [ServiceRole]. Reason: ValidationError: The result of fromAwsManagedPolicyName can not be used in this API [ack: @aws-cdk/core:addConstructMetadataFailed]
Annotations.addMessage (/Users/user/projects/project/node_modules/aws-cdk-lib/core/lib/annotations.js:1:2066)
Annotations.addWarningV2 (/Users/user/projects/project/node_modules/aws-cdk-lib/core/lib/annotations.js:1:984)
addConstructMetadata (/Users/user/projects/project/node_modules/aws-cdk-lib/core/lib/metadata-resource.js:1:1490)
new Role2 (/Users/user/projects/project/node_modules/aws-cdk-lib/aws-iam/lib/role.js:1:12084)
new Role2 (/Users/user/projects/project/node_modules/aws-cdk-lib/core/lib/prop-injectable.js:1:681)
new Function2 (/Users/user/projects/project/node_modules/aws-cdk-lib/aws-lambda/lib/function.js:1:14132)
new Function2 (/Users/user/projects/project/node_modules/aws-cdk-lib/core/lib/prop-injectable.js:1:681)
BucketDeploymentSingletonFunction.ensureLambda (/Users/user/projects/project/node_modules/aws-cdk-lib/aws-lambda/lib/singleton-lambda.js:1:7815)
new SingletonFunction2 (/Users/user/projects/project/node_modules/aws-cdk-lib/aws-lambda/lib/singleton-lambda.js:1:5778)
new SingletonFunction2 (/Users/user/projects/project/node_modules/aws-cdk-lib/core/lib/prop-injectable.js:1:681)
new BucketDeploymentSingletonFunction (/Users/user/projects/project/node_modules/aws-cdk-lib/custom-resource-handlers/dist/aws-s3-deployment/bucket-deployment-provider.generated.js:1:284)
new BucketDeployment2 (/Users/user/projects/project/node_modules/aws-cdk-lib/aws-s3-deployment/lib/bucket-deployment.js:1:5567)
new BucketDeployment2 (/Users/user/projects/project/node_modules/aws-cdk-lib/core/lib/prop-injectable.js:1:681)
deployStaticAssets (/Users/user/projects/project/packages/infrastructure/lib/shared/helpers.ts:149:28)
new AppWebViewStack (/Users/user/projects/project/packages/infrastructure/lib/app-webview-stack.ts:48:23)
stacks (/Users/user/projects/project/packages/infrastructure/bin/infrastructure.ts:209:5)
Object.<anonymous> (/Users/user/projects/project/packages/infrastructure/bin/infrastructure.ts:261:5)
Module._compile (node:internal/modules/cjs/loader:1761:14)
Module.m._compile (/Users/user/projects/project/node_modules/ts-node/src/index.ts:1618:23)
node:internal/modules/cjs/loader:1893:10
Object.require.extensions.<computed> [as .ts] (/Users/user/projects/project/node_modules/ts-node/src/index.ts:1621:12)
Module.load (node:internal/modules/cjs/loader:1481:32)
Module._load (node:internal/modules/cjs/loader:1300:12)
TracingChannel.traceSync (node:diagnostics_channel:328:14)
wrapModuleLoad (node:internal/modules/cjs/loader:245:24)
Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5)
phase4 (/Users/user/projects/project/node_modules/ts-node/src/bin.ts:649:14)
bootstrap (/Users/user/projects/project/node_modules/ts-node/src/bin.ts:95:10)
main (/Users/user/projects/project/node_modules/ts-node/src/bin.ts:55:10)
Object.<anonymous> (/Users/user/projects/project/node_modules/ts-node/src/bin.ts:800:3)
Module._compile (node:internal/modules/cjs/loader:1761:14)
Object.<anonymous> (node:internal/modules/cjs/loader:1893:10)
Module.load (node:internal/modules/cjs/loader:1481:32)
Module._load (node:internal/modules/cjs/loader:1300:12)
TracingChannel.traceSync (node:diagnostics_channel:328:14)
wrapModuleLoad (node:internal/modules/cjs/loader:245:24)
Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5)
node:internal/main/run_main_module:33:47
✨ Synthesis time: 25.22s
[10:47:26] Checking for previously published assets
[10:47:26] project-dev-app-webview-0-stack: debug: Need to perform AWS calls for account redacted, but no credentials have been configured
[10:47:26] project-dev-app-webview-0-stack: debug: Need to perform AWS calls for account redacted, but no credentials have been configured
[10:47:26] project-dev-app-webview-0-stack: debug: Need to perform AWS calls for account redacted, but no credentials have been configured
- Profiling Did not work properly for me
Might be related to https://github.com/nodejs/node/pull/60425