terraform-cdk
terraform-cdk copied to clipboard
cdktf: excessive cost of captureStackTrace
Expected Behavior
I'm using simple TypeScript code to generate my resources and CDKTF constructs. I expected it to be a fast process.
Actual Behavior
When I profiled my script (without even running cdktf synth, jsut the script directly), I see huge overhead in captureStackTrace which is seemingly invoked all the time, whenever I call into a CDK TF routine.
Steps to Reproduce
My repro is private, but if you take a sizeable JavaScript CDKTF project, invoke it as:
$ node --inspect-brk main.js
Then capture a performance trace with Chrome devtools, you'll see captureStackTrace all over the place in leaf nodes.
After that, test my workaround/hypothesis by executing the same command, attaching the chrome debugger, but then executing require('cdktf/lib/tokens/private/stack-trace').captureStackTrace = () => []; in the console before recording the performance profile.
Stubbing out captureStackTrace gives me a 10x speedup (3 seconds vs 300ms) in my CDK TF Stack generation. The synth function of CDKTF after that runs in about the same time, it's unaffected.
Versions
typescript
language: null cdktf-cli: 0.20.8 node: v22.3.0 terraform: 1.9.2 arch: x64 os: linux 6.14.5
Providers
┌─────────────────────┬──────────────────┬─────────┬────────────┬─────────────────────────┬─────────────────┐ │ Provider Name │ Provider Version │ CDKTF │ Constraint │ Package Name │ Package Version │ ├─────────────────────┼──────────────────┼─────────┼────────────┼─────────────────────────┼─────────────────┤ │ local │ │ │ 2.5.2 │ │ │ ├─────────────────────┼──────────────────┼─────────┼────────────┼─────────────────────────┼─────────────────┤ │ petetanton/cachet │ │ │ 0.0.8 │ │ │ ├─────────────────────┼──────────────────┼─────────┼────────────┼─────────────────────────┼─────────────────┤ │ mastercard/restapi │ │ │ 1.19.1 │ │ │ ├─────────────────────┼──────────────────┼─────────┼────────────┼─────────────────────────┼─────────────────┤ │ pagerduty/pagerduty │ │ │ 3.18.1 │ │ │ ├─────────────────────┼──────────────────┼─────────┼────────────┼─────────────────────────┼─────────────────┤ │ datadog/datadog │ 3.44.0 │ ^0.20.0 │ │ @cdktf/provider-datadog │ 11.10.0 │ ├─────────────────────┼──────────────────┼─────────┼────────────┼─────────────────────────┼─────────────────┤ │ tfe │ 0.64.0 │ ^0.20.0 │ │ @cdktf/provider-tfe │ 11.12.0 │ └─────────────────────┴──────────────────┴─────────┴────────────┴─────────────────────────┴─────────────────┘
Gist
No response
Possible Solutions
No response
Workarounds
require('cdktf/lib/tokens/private/stack-trace').captureStackTrace = () => [];
before running the bulk of the work in my CDK Stack generation.
Anything Else?
No response
References
No response
Help Wanted
- [ ] I'm interested in contributing a fix myself
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment