Skip to content
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

Improve BottomUpIndex performance #2367

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

milesziemer
Copy link
Contributor

@milesziemer milesziemer commented Aug 11, 2024

When doing some ad-hoc profiling on the language server using aws service models I noticed that BottomUpIndex was taking up a lot of CPU time. This was because it used selectors and PathFinder to determine the paths from resources/operations up to their enclosing service. Selectors are pretty slow in comparison to regular java code, and when the model is large with many services/operations, this index can take a while to compute. BottomUpIndex is used for validating @cfnResource (through CfnResourcePropertyValidator -> CfnResourceIndex), so anyone using this trait is paying this performance cost (in particular, SDK code generators).

To get a rough idea of how much faster this commit makes BottomUpIndex, I ran model validation using the cli on all aws service models with and without this change a few times each:

smithy validate --quiet # 14 - 16 seconds

/path/to/smithy/smithy-cli/build/image/smithy-cli-darwin-aarch64/bin/smithy
validate --quiet # 8 - 9 seconds

I also added a jmh benchmark for BottomUpIndex (named it KnowledgeIndicies in case we want to add more, but we could keep them separate too and I can change the name). The benchmark results:
Before this change:

KnowledgeIndicies.createsBottomUpIndex  avgt    3  6.300 ± 0.245  us/op

After this change:

KnowledgeIndicies.createsBottomUpIndex  avgt    3  0.467 ± 0.042  us/op

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@milesziemer milesziemer requested a review from a team as a code owner August 11, 2024 17:17
Copy link
Contributor

@JordonPhillips JordonPhillips left a comment

Choose a reason for hiding this comment

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

This looks good, but can you add a jmh benchmark?

Copy link
Contributor

@JordonPhillips JordonPhillips left a comment

Choose a reason for hiding this comment

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

Whoops, set the review to comment instead of request changes

When doing some ad-hoc profiling on the language server using aws
service models I noticed that BottomUpIndex was taking up a lot of CPU
time. This was because it used selectors and PathFinder to determine the
paths from resources/operations up to their enclosing service. Selectors
are pretty slow in comparison to regular java code, and when the model
is large with many services/operations, this index can take a while to
compute. BottomUpIndex is used for validating `@cfnResource` (through
CfnResourcePropertyValidator -> CfnResourceIndex), so anyone using this
trait is paying this performance cost (in particular, SDK code
generators).

To get a rough idea of how much faster this commit makes BottomUpIndex,
I ran model validation using the cli on all aws service models with and
without this change a few times each:
```
smithy validate --quiet # 14 - 16 seconds

/path/to/smithy/smithy-cli/build/image/smithy-cli-darwin-aarch64/bin/smithy
validate --quiet # 8 - 9 seconds
```
@milesziemer milesziemer force-pushed the bottom-up-index-perf branch from d6dfc4e to 8a34fbf Compare August 27, 2024 15:26
@milesziemer milesziemer merged commit d2139b7 into smithy-lang:main Aug 27, 2024
13 checks passed
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