Skip to content

Commit

Permalink
add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
crogoz committed Jan 22, 2025
1 parent a924d17 commit 52712d6
Show file tree
Hide file tree
Showing 39 changed files with 344 additions and 7 deletions.
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ buildscript {
repositories {
mavenCentral() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } }
gradlePluginPortal() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } }
mavenLocal()
}

dependencies {
Expand All @@ -12,14 +13,15 @@ buildscript {
classpath 'com.palantir.gradle.externalpublish:gradle-external-publish-plugin:1.19.0'
classpath 'com.palantir.gradle.failure-reports:gradle-failure-reports:1.13.0'
classpath 'com.palantir.gradle.gitversion:gradle-git-version:3.1.0'
classpath 'com.palantir.gradle.jdks:gradle-jdks:0.59.0'
classpath 'com.palantir.gradle.jdks:gradle-jdks:0.59.0-22-ge6f4332'
classpath 'com.palantir.gradle.jdkslatest:gradle-jdks-latest:0.16.0'
classpath 'com.palantir.gradle.plugintesting:gradle-plugin-testing:0.5.0'
classpath 'com.palantir.javaformat:gradle-palantir-java-format:2.50.0'
classpath 'com.palantir.gradle.revapi:gradle-revapi:1.8.0'
classpath 'com.palantir.javaformat:gradle-palantir-java-format:2.50.0'
classpath 'com.palantir.suppressible-error-prone:gradle-suppressible-error-prone:2.0.0'
classpath 'gradle.plugin.org.inferred:gradle-processors:3.7.0'
classpath 'me.champeau.jmh:jmh-gradle-plugin:0.7.2'
}
}

Expand Down Expand Up @@ -98,4 +100,10 @@ idea.project.ipr.withXml { xml ->

jdks {
daemonTarget = 17

jdk(23) {
distribution = 'graalvm-ce'
jdkVersion = '23.0.1'
}

}
4 changes: 2 additions & 2 deletions gradle/gradle-jdks-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ install_and_setup_jdks() {
case "$distribution_url" in
*.zip)
distribution_name=${distribution_url##*/}
curl -C - "$distribution_url" -o "$distribution_name"
curl -L -C - "$distribution_url" -o "$distribution_name"
tar -xzf "$distribution_name"
;;
*)
curl -C - "$distribution_url" | tar -xzf -
curl -L -C - "$distribution_url" | tar -xzf -
;;
esac
elif command -v wget > /dev/null 2>&1; then
Expand Down
Binary file modified gradle/gradle-jdks-setup.jar
Binary file not shown.
1 change: 1 addition & 0 deletions gradle/jdks/23/linux-glibc/aarch64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-23.0.1/graalvm-community-jdk-23.0.1_linux-aarch64_bin.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/23/linux-glibc/aarch64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graalvm-ce-23.0.1-glibc
1 change: 1 addition & 0 deletions gradle/jdks/23/linux-glibc/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-23.0.1/graalvm-community-jdk-23.0.1_linux-x64_bin.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/23/linux-glibc/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graalvm-ce-23.0.1-glibc
1 change: 1 addition & 0 deletions gradle/jdks/23/linux-glibc/x86/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-23.0.1/graalvm-community-jdk-23.0.1_linux-x64_bin.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/23/linux-glibc/x86/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graalvm-ce-23.0.1-glibc
1 change: 1 addition & 0 deletions gradle/jdks/23/linux-musl/aarch64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-23.0.1/graalvm-community-jdk-23.0.1_linux-aarch64_bin.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/23/linux-musl/aarch64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graalvm-ce-23.0.1-musl
1 change: 1 addition & 0 deletions gradle/jdks/23/linux-musl/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-23.0.1/graalvm-community-jdk-23.0.1_linux-x64_bin.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/23/linux-musl/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graalvm-ce-23.0.1-musl
1 change: 1 addition & 0 deletions gradle/jdks/23/linux-musl/x86/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-23.0.1/graalvm-community-jdk-23.0.1_linux-x64_bin.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/23/linux-musl/x86/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graalvm-ce-23.0.1-musl
1 change: 1 addition & 0 deletions gradle/jdks/23/macos/aarch64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-23.0.1/graalvm-community-jdk-23.0.1_macos-aarch64_bin.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/23/macos/aarch64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graalvm-ce-23.0.1
1 change: 1 addition & 0 deletions gradle/jdks/23/macos/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-23.0.1/graalvm-community-jdk-23.0.1_macos-x64_bin.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/23/macos/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graalvm-ce-23.0.1
1 change: 1 addition & 0 deletions gradle/jdks/23/macos/x86/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-23.0.1/graalvm-community-jdk-23.0.1_macos-x64_bin.tar.gz
1 change: 1 addition & 0 deletions gradle/jdks/23/macos/x86/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graalvm-ce-23.0.1
1 change: 1 addition & 0 deletions gradle/jdks/23/windows/aarch64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-23.0.1/graalvm-community-jdk-23.0.1_windows-aarch64_bin.zip
1 change: 1 addition & 0 deletions gradle/jdks/23/windows/aarch64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graalvm-ce-23.0.1
1 change: 1 addition & 0 deletions gradle/jdks/23/windows/x86-64/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-23.0.1/graalvm-community-jdk-23.0.1_windows-x64_bin.zip
1 change: 1 addition & 0 deletions gradle/jdks/23/windows/x86-64/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graalvm-ce-23.0.1
1 change: 1 addition & 0 deletions gradle/jdks/23/windows/x86/download-url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-23.0.1/graalvm-community-jdk-23.0.1_windows-x64_bin.zip
1 change: 1 addition & 0 deletions gradle/jdks/23/windows/x86/local-path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graalvm-ce-23.0.1
26 changes: 26 additions & 0 deletions palantir-java-format-benchmarks/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apply plugin: 'distribution'
apply plugin: 'me.champeau.jmh'

dependencies {
jmhAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess'
compileOnly 'org.openjdk.jmh:jmh-generator-annprocess'

jmhImplementation 'org.assertj:assertj-core'
jmhImplementation 'org.junit.jupiter:junit-jupiter'
jmhImplementation 'org.openjdk.jmh:jmh-core'
jmhImplementation 'org.openjdk.jmh:jmh-generator-annprocess'
}

tasks.withType(ProcessResources.class).configureEach {
from(project(':palantir-java-format').tasks.named('fatJar')) {
rename { 'palantir-java-format-all.jar' }
}
}

jmhCompileGeneratedClasses {
options.errorprone.enabled = false
}

tasks.named("jmh") {
dependsOn ":palantir-java-format:nativeCompile", ":palantir-java-format:fatJar"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* (c) Copyright 2025 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.javaformat;

import static org.assertj.core.api.Assertions.assertThat;

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.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.OptionsBuilder;

@Measurement(iterations = 2, time = 2)
//@Warmup(iterations = 2, time = 4)
public class BenchmarkMultiFiles {

@State(Scope.Benchmark)
public static class BenchmarkState {

final List<String> filesToFormat = getFilesToFormat();

private static List<String> getFilesToFormat() {
Path srcJavaFormatFiles = Paths.get(".")
.toAbsolutePath()
.resolve("../palantir-java-format/src/main/java/com/palantir/javaformat/java");
try (Stream<String> paths = Files.list(srcJavaFormatFiles)
.filter(Files::isRegularFile)
.map(path -> path.toAbsolutePath().toString())) {
return paths.collect(Collectors.toList());
} catch (IOException e) {
throw new RuntimeException("Couldn't list src files: " + srcJavaFormatFiles, e);
}
}
}

@Benchmark
@BenchmarkMode(Mode.All)
@OutputTimeUnit(TimeUnit.SECONDS)
public final void runNativeImage(BenchmarkState state) throws InterruptedException, IOException {
ProcessBuilder p = new ProcessBuilder();
p.command(Stream.concat(
Stream.of(
Path.of(".")
.toAbsolutePath()
.resolve("../palantir-java-format/build/graal/palantir-java-format")
.toString(),
"-i",
"--palantir"),
state.filesToFormat.stream())
.collect(Collectors.toList()));
Process process = p.inheritIO().start();
assertThat(process.waitFor()).isEqualTo(0);
}

@Benchmark
@BenchmarkMode(Mode.All)
@OutputTimeUnit(TimeUnit.SECONDS)
public final void runJar(BenchmarkState state) throws InterruptedException, IOException {
ProcessBuilder p = new ProcessBuilder();
p.command(Stream.concat(
Stream.of(
"java",
"-jar",
Paths.get(".")
.toAbsolutePath()
.resolve("build/resources/jmh/palantir-java-format-all.jar")
.toString(),
"-i",
"--palantir"),
state.filesToFormat.stream())
.collect(Collectors.toList()));
Process process = p.inheritIO().start();
assertThat(process.waitFor()).isEqualTo(0);
}

public static void main(String[] _args) throws RunnerException {
new Runner(new OptionsBuilder()
.include(BenchmarkMultiFiles.class.getSimpleName())
.build())
.run();
}
}
58 changes: 58 additions & 0 deletions palantir-java-format/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
buildscript {
repositories {
mavenCentral() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } }
gradlePluginPortal() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } }
}
dependencies {
classpath 'org.graalvm.buildtools:native-gradle-plugin:0.10.4'
}
}

apply plugin: 'org.graalvm.buildtools.native'
apply plugin: 'application'
apply plugin: 'com.palantir.external-publish-jar'

Expand Down Expand Up @@ -30,6 +41,36 @@ dependencies {
annotationProcessor 'org.derive4j:derive4j'
}

graalvmNative {
binaries {
main {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(23)
vendor = JvmVendorSpec.GRAAL_VM
}
imageName = 'palantir-java-format'
mainClass = mainClassName
fallback = false
sharedLibrary = false
configurationFileDirectories.from(file('src/main/resources/META-INF/native-image'))
buildArgs.addAll("-H:ConfigurationFileDirectories=${projectDir}/src/main/resources/META-INF/native-image",
'-H:+UnlockExperimentalVMOptions',
'-H:IncludeResourceBundles=com.sun.tools.javac.resources.compiler',
'-H:IncludeResourceBundles=com.sun.tools.javac.resources.javac',
'--no-fallback',
'--initialize-at-build-time=com.sun.tools.javac.file.Locations',
'-H:+ReportExceptionStackTraces',
'-H:-UseContainerSupport',
'-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
'-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
'-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
'-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
'-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED')
}
}
}

def exports = [
'jdk.compiler/com.sun.tools.javac.file',
'jdk.compiler/com.sun.tools.javac.main',
Expand Down Expand Up @@ -89,3 +130,20 @@ tasks.named("jar", Jar) {
attributes('Add-Exports': exports.join(' '))
}
}

tasks.register('fatJar', Jar) {
dependsOn tasks.jar, project(':palantir-java-format-spi').tasks.jar
manifest {
attributes 'Main-Class': mainClassName
attributes('Add-Exports': exports.join(' '))
}
archiveBaseName = 'palantir-java-format-all'
duplicatesStrategy = DuplicatesStrategy.WARN
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}


tasks.named("build") {
dependsOn tasks.named("fatJar"), tasks.named("nativeCompile")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name":"com.palantir.javaformat.java.Main",
"methods":[{"name":"main","parameterTypes":["java.lang.String[]"] }]
},
{
"name":"java.lang.Boolean",
"methods":[{"name":"getBoolean","parameterTypes":["java.lang.String"] }]
},
{
"name":"java.lang.String",
"methods":[{"name":"lastIndexOf","parameterTypes":["int"] }, {"name":"substring","parameterTypes":["int"] }]
},
{
"name":"java.lang.System",
"methods":[{"name":"getProperty","parameterTypes":["java.lang.String"] }, {"name":"setProperty","parameterTypes":["java.lang.String","java.lang.String"] }]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"type":"agent-extracted",
"classes":[
]
}
]

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"name":"[Lcom.fasterxml.jackson.databind.deser.Deserializers;"
},
{
"name":"[Lcom.fasterxml.jackson.databind.ser.BeanSerializerModifier;"
},
{
"name":"[Lcom.fasterxml.jackson.databind.ser.Serializers;"
},
{
"name":"com.fasterxml.jackson.databind.ext.Java7SupportImpl",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.palantir.javaformat.java.JavacTokens$CommentSavingTokenizer"
},
{
"name":"com.palantir.javaformat.java.java14.Java14InputAstVisitor",
"methods":[{"name":"<init>","parameterTypes":["com.palantir.javaformat.OpsBuilder","int"] }]
},
{
"name":"com.sun.source.tree.BindingPatternTree",
"methods":[{"name":"getBinding","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }, {"name":"getVariable","parameterTypes":[] }]
},
{
"name":"com.sun.source.tree.CaseTree",
"methods":[{"name":"getLabels","parameterTypes":[] }]
},
{
"name":"com.sun.source.tree.ClassTree",
"methods":[{"name":"getPermitsClause","parameterTypes":[] }]
},
{
"name":"com.sun.source.tree.CompilationUnitTree",
"methods":[{"name":"getModule","parameterTypes":[] }]
},
{
"name":"com.sun.tools.javac.parser.JavaTokenizer",
"fields":[{"name":"reader"}]
},
{
"name":"com.sun.tools.javac.parser.UnicodeReader",
"methods":[{"name":"getRawCharacters","parameterTypes":["int","int"] }]
},
{
"name":"java.util.concurrent.atomic.AtomicReference",
"fields":[{"name":"value"}]
}
]
Loading

0 comments on commit 52712d6

Please sign in to comment.