Skip to content

Conversation

JordonPhillips
Copy link
Contributor

@JordonPhillips JordonPhillips commented Sep 10, 2025

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:
Screenshot 2025-09-11 at 10 32 58

And here's output for the new:
Screenshot 2025-09-11 at 10 26 08

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.

@JordonPhillips JordonPhillips requested a review from a team as a code owner September 10, 2025 21:26
@JordonPhillips JordonPhillips marked this pull request as draft September 10, 2025 21:26
{
"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": []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I gotta update this

@JordonPhillips JordonPhillips force-pushed the plugin-ordering branch 2 times, most recently from 4bd3c5b to 0a992d7 Compare September 12, 2025 14:00
@JordonPhillips JordonPhillips marked this pull request as ready for review September 17, 2025 14:47
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.
Copy link
Contributor

@kstich kstich left a 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.

Comment on lines +23 to +25
@Override
public boolean isSerial() {
return true;
Copy link
Contributor

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?

Copy link
Contributor Author

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(
Copy link
Contributor

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 -

public static final class CycleException extends RuntimeException {

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants