-
Notifications
You must be signed in to change notification settings - Fork 239
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
6740b0e
to
5eb3729
Compare
...hy-codegen-core/src/jmh/java/software/amazon/smithy/codegen/core/jmh/SmithyIntegrations.java
Show resolved
Hide resolved
...hy-codegen-core/src/jmh/java/software/amazon/smithy/codegen/core/jmh/SmithyIntegrations.java
Show resolved
Hide resolved
...degen-core/src/main/java/software/amazon/smithy/codegen/core/IntegrationTopologicalSort.java
Outdated
Show resolved
Hide resolved
smithy-utils/src/main/java/software/amazon/smithy/utils/DependencyGraph.java
Outdated
Show resolved
Hide resolved
4bd3c5b
to
0a992d7
Compare
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.
This adds the concept of dependencies to build plugins. Plugins can now declare that they must be run before or after some plugins. This uses the same dependency graph that is used by SmithyIntegration, but unlike integrations there is no concept of a "priority". This is because we may want to be able to run the plugins themselves in parallell, and such a priority would complicate that.
5e7393c
to
c74510b
Compare
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 know there are a couple other places that use topological sorting, TopologicalShapeSort
and TopologicalIndex
at least. TopologicalIndex
requires pulling cycles out and storing them, so I don't think it can migrate to this. TopologicalShapeSort
looks like it could, though.
@Override | ||
public boolean isSerial() { | ||
return true; |
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 think there's a reliance on these plugins being serial, but all of them are listed that way. Can these be non-serial (my read is they can) or is it a secret dependency on this behavior?
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 is in case we ever decide to run plugins in parallel. We don't now, but we could.
remaining.add(node.toString()); | ||
} | ||
} | ||
throw new IllegalStateException( |
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.
What about using this detailed exception from TopologicalShapeSort
-
smithy/smithy-model/src/main/java/software/amazon/smithy/model/loader/TopologicalShapeSort.java
Line 116 in 426c1ef
public static final class CycleException extends RuntimeException { |
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 can use something like that, but I can't use that since smithy-model depends on smithy-utils, not the other way around.
This adds a new
DependencyGraph
to smithy-utils, intended for use in the numerous locations where we perform topological sorts.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.
Here's benchmarking output for the old integration sort:

And here's output for the new:

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.