-
Notifications
You must be signed in to change notification settings - Fork 238
Add generic depdency graph implementation to smithy-utils and use it for handling topological sorting #2774
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
base: main
Are you sure you want to change the base?
Conversation
{ | ||
"type": "feature", | ||
"description": "Add a generic dependency graph to smithy-utils to be used for sorting various dependent objects, such as integrations and plugins.", | ||
"pull_requests": [] |
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 gotta update this
This adds a generic dependency graph to smithy-utils. This is intended to be used to sort SmithyIntegrations, SmithyBuildPlugins, and anything else that needs a topological sort.
This updates the SmithyIntegration sorting to use the generic DependencyGraph. It also adds some benchmarking configurations, which show a minor speed bump for highly dependent integrations and a major speed bump for highly independent integrations.
6740b0e
to
5eb3729
Compare
} | ||
independentIntegrations1000.put(name, integration); | ||
} | ||
independentIntegrations100 = Collections.unmodifiableMap(independentIntegrations100); |
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.
Why is only the 100
sized map being made unmodifiable?
@Measurement(iterations = 3, timeUnit = TimeUnit.MICROSECONDS) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@Fork(1) | ||
public class SmithyIntegrations { |
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 don't see these benchmarks providing a before/after of the sorting in codegen-core
, and the PR overview doesn't show the difference between before/after of SmithyIntegration.sort
's performance. Am I missing something?
|
||
private final Queue<String> satisfied = new PriorityQueue<>((left, right) -> { | ||
private final DependencyGraph<String> dependencyGraph = new DependencyGraph<>(); | ||
private final Comparator<String> comparator = (left, right) -> { |
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.
This should be a method that can be referenced instead of an anonymous function.
* | ||
* <p>If any node is not already present in the graph, it is added. | ||
* | ||
* @param what The node to add dependencies to to. |
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.
* @param what The node to add dependencies to to. | |
* @param what The node to add dependencies to. |
This adds a new
DependencyGraph
to smithy-utils, intended for use in the numerous locations where we perform topological sorts.Currently this only being used in
SmithyIntegration.sort
, but I want to add it to other places where we do topological sorts before I take this out of draft. So far, performance seems promising. Performance-wise, it's a bit faster for dense graphs (integrations with lots of dependencies) and a bit slower for sparse graphs. In the sizes we're realistically looking at for integrations (dozens, tops) the difference is insignificant. We're talking about a microsecond or two.I also plan to add the same sort of ordering capabilities to smithy build plugins, which is why I've gone to the trouble to make this generic.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.