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.

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.

@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

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.
}
independentIntegrations1000.put(name, integration);
}
independentIntegrations100 = Collections.unmodifiableMap(independentIntegrations100);
Copy link
Contributor

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 {
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 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) -> {
Copy link
Contributor

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

Choose a reason for hiding this comment

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

Suggested change
* @param what The node to add dependencies to to.
* @param what The node to add dependencies to.

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