forked from smithy-lang/smithy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 ```
- Loading branch information
1 parent
5f07427
commit 8a34fbf
Showing
2 changed files
with
81 additions
and
20 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
smithy-model/src/jmh/java/software/amazon/smithy/model/jmh/KnowledgeIndicies.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.model.jmh; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.knowledge.BottomUpIndex; | ||
|
||
@Warmup(iterations = 3) | ||
@Measurement(iterations = 3, timeUnit = TimeUnit.MICROSECONDS) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@Fork(1) | ||
public class KnowledgeIndicies { | ||
@State(Scope.Thread) | ||
public static class IndiciesState { | ||
public Model model; | ||
|
||
@Setup | ||
public void prepare() { | ||
model = Model.assembler() | ||
.addImport(KnowledgeIndicies.class.getResource("test-model.smithy")) | ||
.disableValidation() | ||
.assemble() | ||
.getResult() | ||
.get(); | ||
} | ||
} | ||
|
||
@Benchmark | ||
public BottomUpIndex createsBottomUpIndex(IndiciesState state) { | ||
// Use the ctor so the index doesn't get cached in warmup runs and re-used | ||
return new BottomUpIndex(state.model); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters