-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix: synthesis fails if tree.json exceeds 512MB
#34478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
35ebdaa
fix: synthesis fails if tree.json exceeds 512MB
rix0rrr 92e180a
Undo all the changes that have to do with performance improvements of…
rix0rrr 79fdace
DFS preorder is not used in this PR
rix0rrr 6f37d38
Merge branch 'main' into huijbers/split-tree
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/aws-cdk-lib/core/lib/private/construct-iteration.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { IConstruct } from 'constructs'; | ||
| import { LinkedQueue } from './linked-queue'; | ||
|
|
||
| /** | ||
| * Breadth-first iterator over the construct tree | ||
| */ | ||
| export function* iterateBfs(root: IConstruct) { | ||
| // Use a specialized queue data structure. Using `Array.shift()` | ||
| // has a huge performance penalty (difference on the order of | ||
| // ~50ms vs ~1s to iterate a large construct tree) | ||
| const queue = new LinkedQueue<{ construct: IConstruct; parent: IConstruct | undefined }>([{ construct: root, parent: undefined }]); | ||
|
|
||
| let next = queue.shift(); | ||
| while (next) { | ||
| for (const child of next.construct.node.children) { | ||
| queue.push({ construct: child, parent: next.construct }); | ||
| } | ||
| yield next; | ||
|
|
||
| next = queue.shift(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /** | ||
| * A queue that is faster than an array at large throughput | ||
| */ | ||
| export class LinkedQueue<A> { | ||
| private head?: Node<A>; | ||
| private last?: Node<A>; | ||
|
|
||
| constructor(items?: Iterable<A>) { | ||
| if (items) { | ||
| for (const x of items) { | ||
| this.push(x); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public push(value: A) { | ||
| const node: Node<A> = { value }; | ||
| if (this.head && this.last) { | ||
| this.last.next = node; | ||
| this.last = node; | ||
| } else { | ||
| this.head = node; | ||
| this.last = node; | ||
| } | ||
| } | ||
|
|
||
| public shift(): A | undefined { | ||
| if (!this.head) { | ||
| return undefined; | ||
| } | ||
| const ret = this.head.value; | ||
|
|
||
| this.head = this.head.next; | ||
| if (!this.head) { | ||
| this.last = undefined; | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
| } | ||
|
|
||
| interface Node<A> { | ||
| value: A; | ||
| next?: Node<A>; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few improvements
for use as
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite comfortable adding these methods that we wouldn't be using.
length/isEmpty: sure, I guess. Though if possible I prefer coding style of the form "do, then check" rather than "will next call succeed / do next call". This is a style that will avoid TOCTOU's without having to constantly mentally think about whether you are in a situation where it does or does not apply.clear: not using it, so why add it?iterator: I'm not comfortable writing aforloop over a data structure that gets mutated. I understand we could code the list to make that work, but I would get uneasy seeing the client side of that code, since it relies on too many unknowns.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment was to make it a more general purpose ds. This is great for the current ask.