Skip to content

fix(core): token stack traces expensively clutter --debug mode#37642

Merged
mergify[bot] merged 6 commits into
mainfrom
huijbers/no-token-traces
Apr 20, 2026
Merged

fix(core): token stack traces expensively clutter --debug mode#37642
mergify[bot] merged 6 commits into
mainfrom
huijbers/no-token-traces

Conversation

@rix0rrr

@rix0rrr rix0rrr commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Capturing stack traces is an expensive operation. It only happens in --debug mode (CDK_DEBUG=1) so most normal executions don't pay this cost, but we want to start using debug mode more often to get useful trace information out of CDK apps.

Right now, when debug mode is enabled, stack traces will be captured at every Token creation site. A typical CDK app will create 1000s-10s of thousands of Tokens, and each creation would require capturing a stack trace that will almost certainly never be used.

Deprecate and disable token stack traces. This will make normal execution sliiiightly faster (probably unnoticeably so) and make --debug mode execution notably faster.

For heavily used tokens from the core library we move the allocation of the stack trace to the prototype instead of the instance, to save that additional tiny extra bit of memory allocation of a static array on every token instantiation.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Capturing stack traces is an expensive operation. It only happens in
`--debug` mode (`CDK_DEBUG=1`) so most normal executions don't pay this
cost, but we want to start using debug mode more often to get useful
trace information out of CDK apps.

Right now, when debug mode is enabled, stack traces will be captured at
every Token creation site. A typical CDK app will create 1000s-10s of
thousands of Tokens, and each creation would require capturing a stack
trace that will almost certainly never be used.

Deprecate and disable token stack traces. This will make normal
execution sliiiightly faster (probably unnoticeably so) and make
`--debug` mode execution notably faster.

For heavily used tokens from the `core` library we move the allocation
of the stack trace to the prototype instead of the instance, to save
that additional tiny extra bit of memory allocation of a static array on
every token instantiation.
@rix0rrr rix0rrr requested a review from a team as a code owner April 20, 2026 09:07
@github-actions github-actions Bot added the p2 label Apr 20, 2026
@aws-cdk-automation aws-cdk-automation requested a review from a team April 20, 2026 09:07
@mergify mergify Bot added the contribution/core This is a PR that came from AWS. label Apr 20, 2026

@aws-cdk-automation aws-cdk-automation left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@rix0rrr rix0rrr added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Apr 20, 2026
@aws-cdk-automation aws-cdk-automation dismissed their stale review April 20, 2026 09:35

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

*/
public readonly displayHint: string;
public readonly creationStack: string[];
public readonly creationStack: string[] = ['Token stack traces are deprecated'];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me "deprecated" implies it can still be used somehow but will go away in the next major version. Maybe we can update the wording here (and in the other places).

@mrgrain mrgrain added the pr/do-not-merge This PR should not be merged at this time. label Apr 20, 2026
@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Apr 20, 2026
@mergify

mergify Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify

mergify Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • Entered queue2026-04-20 16:55 UTC · Rule: default-squash
  • Checks passed · in-place
  • Merged2026-04-20 17:27 UTC · at 20ff9b62f145351c7072082cfa1382e9236d5fb1 · squash

This pull request spent 31 minutes 54 seconds in the queue, including 31 minutes 40 seconds running CI.

Required conditions to merge

@mergify

mergify Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify Bot merged commit 498c546 into main Apr 20, 2026
19 of 20 checks passed
@mergify mergify Bot deleted the huijbers/no-token-traces branch April 20, 2026 17:27
@github-actions

Copy link
Copy Markdown
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

contribution/core This is a PR that came from AWS. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants