Repository navigation
feat(CI): Set up CodSpeed #241
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e6768c5
gotta go fast
emyller 3ddae20
where's maven?
emyller e225ddb
no leaking
emyller 35f7576
make
emyller b08b14d
benchmark the sdk interface
emyller 2a7daa6
make local benchmarking great again
emyller b0159d3
not much of an interface eh
emyller acf35b4
needless verification
emyller d2116b8
shared layer of benchmark data
emyller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,42 @@ | ||
| name: CodSpeed | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read # Check out the repository and its submodules | ||
| id-token: write # Authenticate result uploads to CodSpeed via OIDC | ||
|
|
||
| jobs: | ||
| benchmarks: | ||
| name: Run benchmarks | ||
| runs-on: codspeed-macro | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| submodules: recursive | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up JDK | ||
| uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0 | ||
| with: | ||
| distribution: temurin | ||
| java-version: 21 | ||
| cache: maven | ||
|
|
||
| - name: Set up Maven | ||
| uses: stCarolas/setup-maven@12eb41b233df95d49b0c11fc1b5bc8312e5d4ce0 # v5.1 | ||
| with: | ||
| maven-version: 3.10.0 | ||
|
|
||
| - name: Run benchmarks | ||
| uses: CodSpeedHQ/action@78102a468f96d8e0ccb92d0ec49425753fc42062 # v5.6.0 | ||
| with: | ||
| mode: walltime | ||
| run: make benchmark | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| [submodule "src/test/java/com/flagsmith/flagengine/enginetestdata"] | ||
| path = src/test/java/com/flagsmith/flagengine/enginetestdata | ||
| url = git@github.com:Flagsmith/engine-test-data.git | ||
| branch = v3.7.0 | ||
| branch = v3.7.0 | ||
| [submodule "third-party/codspeed-jvm"] | ||
| path = third-party/codspeed-jvm | ||
| url = https://github.com/CodSpeedHQ/codspeed-jvm.git |
This file contains hidden or 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,9 @@ | ||
| BENCHMARKS_JAR ?= target/benchmarks.jar | ||
|
|
||
| $(BENCHMARKS_JAR): pom.xml $(shell find src/main src/jmh -type f) | ||
| cd third-party/codspeed-jvm && ./gradlew -p jmh-fork publishToMavenLocal | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| mvn --batch-mode --no-transfer-progress -P benchmarks -DskipTests package | ||
|
|
||
| .PHONY: benchmark | ||
| benchmark: $(BENCHMARKS_JAR) | ||
| java -jar $(BENCHMARKS_JAR) | ||
This file contains hidden or 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
67 changes: 67 additions & 0 deletions
67
src/jmh/java/com/flagsmith/flagengine/EngineBenchmark.java
|
khvn26 marked this conversation as resolved.
Resolved
|
This file contains hidden or 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,67 @@ | ||
| package com.flagsmith.flagengine; | ||
|
|
||
| import com.fasterxml.jackson.core.json.JsonReadFeature; | ||
| import com.fasterxml.jackson.databind.json.JsonMapper; | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
| import org.openjdk.jmh.annotations.Benchmark; | ||
| import org.openjdk.jmh.annotations.Scope; | ||
| import org.openjdk.jmh.annotations.Setup; | ||
| import org.openjdk.jmh.annotations.State; | ||
| import org.openjdk.jmh.infra.Blackhole; | ||
|
|
||
| /** | ||
| * Benchmarks local flag evaluation against every engine test data case. | ||
| */ | ||
| @State(Scope.Benchmark) | ||
| public class EngineBenchmark { | ||
| private static final Path testCasesPath = Paths | ||
| .get("src/test/java/com/flagsmith/flagengine/enginetestdata/test_cases"); | ||
| private static final JsonMapper mapper = JsonMapper.builder() | ||
| .enable(JsonReadFeature.ALLOW_JAVA_COMMENTS.mappedFeature()) | ||
| .build(); | ||
|
|
||
| private List<EvaluationContext> evaluationContexts; | ||
|
|
||
| /** | ||
| * Load the evaluation contexts from the engine test data. | ||
| */ | ||
| @Setup | ||
| public void loadEvaluationContexts() throws IOException { | ||
| try (Stream<Path> paths = Files.walk(testCasesPath)) { | ||
| evaluationContexts = paths | ||
| .filter(Files::isRegularFile) | ||
| .filter(p -> { | ||
| String n = p.getFileName().toString(); | ||
| return n.endsWith(".json") || n.endsWith(".jsonc"); | ||
| }) | ||
| .sorted() | ||
| .map(EngineBenchmark::evaluationContextFromFile) | ||
| .collect(Collectors.toList()); | ||
| } | ||
| } | ||
|
|
||
| private static EvaluationContext evaluationContextFromFile(Path path) { | ||
| try (BufferedReader reader = Files.newBufferedReader(path)) { | ||
| return mapper.treeToValue(mapper.readTree(reader).get("context"), EvaluationContext.class); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException("Failed to read test data from file: " + path, e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Evaluate flags for every engine test data case. | ||
| */ | ||
| @Benchmark | ||
| public void evaluateEngineTestCases(Blackhole blackhole) { | ||
| for (EvaluationContext evaluationContext : evaluationContexts) { | ||
| blackhole.consume(Engine.getEvaluationResult(evaluationContext)); | ||
| } | ||
| } | ||
|
khvn26 marked this conversation as resolved.
Resolved
|
||
| } | ||
|
khvn26 marked this conversation as resolved.
Resolved
|
Submodule codspeed-jvm
added at
af05f6
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.