Repository navigation
fix(core): stack.node.addDependency gets slower as stacks grow - #38314
Conversation
Because there are multiple dependency types, reword some methods to make the distinction clear: - `stack.addDependency(stack)`: now called `addStackDependency` - `res.addDependency(res)`: now called `addResourceDependency`
|
PRs without a linked issue will receive lower priority for review and merging. Please update the description to follow the PR template and include a line like |
ShadowCat567
left a comment
There was a problem hiding this comment.
Looks reasonable, some tests relating to disallowing parent/child dependencies (parent target/child source) are still broken
| * | ||
| * @internal | ||
| */ | ||
| public _addAssemblyDependency(target: Stack, reason: StackDependencyReason = {}) { |
There was a problem hiding this comment.
Why can we remove these _[add/remove/obtain]AssemblyDependency methods? Does _[add/remove/obtain]StackDependency do the work the assemblyDependency method used to do?
There was a problem hiding this comment.
The work has now been diffused between dispatchDependencyOperation (check most of the prerequisites, except cycles) and _addStackDependency.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
|
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). |
Merge Queue Status
This pull request spent 35 minutes 51 seconds in the queue, including 35 minutes 32 seconds running CI. Required conditions to merge
|
|
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). |
|
Comments on closed issues and PRs are hard for our team to see. |
source.node.addDependency(target)is used to confer dependencies between all resources undersourceto all resources undertarget.The way this was done is to first expand the two sets into a Cartesian product, and then apply the dependency individually for each pair. The applied dependency can lead to a CloudFormation
DependsOnrelationship between the target resource (or the Nested Stack containing it), or a Stack-to-Stack dependency if the resources are in different stacks.However, if this method of adding dependencies is applied to Stacks, we would first make all pairs of resources from
(sourceStack, targetStack), apply the dependency, and find out that each of those dependencies would ultimately just lead to a single stack-to-stack dependency. This method of applying dependencies is quadratic in the size of the stack, whereas it should be linear in the number of stack-to-stack dependencies applied.In this PR, we rework the dependencies mechanism to remove the quadraticness if
node.addDependencyis used to add dependencies between stacks: we resolve the constructs that should be involved in the dependency operation first, and only expand to the cartesian product of individual resources if we end up inside the same Stack (in which case the construct groups are on the order of single digits). This makes the cross-stack case a lot faster.(Note: I'm saying "superlinear" in the body because although it seems like the work should be quadratic, from testing it seems to be a lot worse than quadratic -- perhaps even exponential. In any case anything worse than linear is baaaaaddd so that's what I'm writing it down as 😉 )
Because there are multiple ways of adding dependencies, renamed some of them to make the distinction more clear:
construct.node.addDependency(construct): add a construct-level description of a dependency that will get reified at synthesis time.removeDependencyhere: feat: removeDependency constructs#2872stack.addStackDependency(stack),resource.addResourceDependency(resource): directly applies a dependencies between stacks or resources.stack.addDependencyandresource.addDependency, which is confusing because nowstack.addDependencyandstack.node.addDependencylook very similar but do very different things. So I renamed them.resource.addResourceDependencyalso performs for cross-stack dependencies, which I'd much prefer it hadn't so it could stay simple and predictable, but we can't take this away anymore._addStackDependency,_addResourceDependencyetc.The flow is now this:
Everything dispatches through the same code so that the behavior is the same regardless of the entry API that is chosen.
CHEAKING BRANGE: This PR removes
obtainResourceDependencies; this was used as an internal function with nonstandard semantics. It has been moved to fully internal and is no longer usable externally (using different words because there is no way for me to format the PR title for a break in a way that the PR linter accepts). I triedfix!:`` andfix(core)!` and it keeps on complaining that there's something wrong. So I'm giving up.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license