Skip to content

Commit 590dd0a

Browse files
committed
perf
1 parent b7d2c98 commit 590dd0a

4 files changed

Lines changed: 114 additions & 90 deletions

File tree

palantir-java-format-benchmarks/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ tasks.named('jmh', JMHTask.class) {
3131
environment.put('JARS_CLASSPATH', configurations.named('formatterNativeJars').map { conf -> conf.collect { it.absolutePath }.join(":") })
3232
}
3333

34+
spotless {
35+
java {
36+
targetExclude 'src/test/resources/*'
37+
}
38+
}
39+
3440
jmhCompileGeneratedClasses {
3541
options.errorprone.enabled = false
3642
}

palantir-java-format-benchmarks/src/jmh/java/com/palantir/javaformat/BenchmarkMultiFiles.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ private static List<String> getFilesToFormat() {
6262
}
6363
}
6464

65+
@State(Scope.Benchmark)
66+
public static class MultiLevelStates {
67+
68+
final String fileToFormat = getFileToFormat();
69+
70+
private static String getFileToFormat() {
71+
try {
72+
return Paths.get(".")
73+
.resolve("src/test/resources/PalantirDeeplyNestedCalls.java")
74+
.toAbsolutePath()
75+
.toString();
76+
} catch (Exception e) {
77+
throw new RuntimeException("Error reading resource ", e);
78+
}
79+
}
80+
}
81+
6582
@Benchmark
6683
@BenchmarkMode(Mode.All)
6784
@OutputTimeUnit(TimeUnit.SECONDS)
@@ -76,6 +93,17 @@ public final void runNativeImage(BenchmarkState state) throws InterruptedExcepti
7693
assertThat(process.waitFor()).isEqualTo(0);
7794
}
7895

96+
@Benchmark
97+
@BenchmarkMode(Mode.AverageTime)
98+
@OutputTimeUnit(TimeUnit.SECONDS)
99+
public final void runNestedLevel(MultiLevelStates state) throws InterruptedException, IOException {
100+
ProcessBuilder p = new ProcessBuilder();
101+
p.command(List.of(
102+
Path.of(System.getenv("NATIVE_IMAGE_CLASSPATH")).toString(), "-i", "--palantir", state.fileToFormat));
103+
Process process = p.inheritIO().start();
104+
assertThat(process.waitFor()).isEqualTo(0);
105+
}
106+
79107
@Benchmark
80108
@BenchmarkMode(Mode.All)
81109
@OutputTimeUnit(TimeUnit.SECONDS)
@@ -102,8 +130,8 @@ public final void runJar(BenchmarkState state) throws InterruptedException, IOEx
102130

103131
public static void main(String[] _args) throws RunnerException {
104132
new Runner(new OptionsBuilder()
105-
.include(BenchmarkMultiFiles.class.getSimpleName())
106-
.build())
133+
.include(BenchmarkMultiFiles.class.getSimpleName())
134+
.build())
107135
.run();
108136
}
109137
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Volumes/git/palantir-java-format/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/palantir-deeply-nested-calls.input

palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/palantir-deeply-nested-calls.input

Lines changed: 77 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -13,92 +13,81 @@ class PalantirDeeplyNestedCalls {
1313
.build()))
1414
.build();
1515

16+
void testMethod() {
17+
assertThat(ConfigServiceV1.getAllItems(item1, item2, item3, item4))
18+
.containsExactlyInAnyOrderElementsOf(Set.of(
19+
new ItemWithCustomLocator(
20+
ItemConfigV1.DEFAULT_CONFIG.toCustomString(),
21+
ItemConfigV1.createCustomConfig(ItemConfigV1Locator.of(TEST_ITEM_A))),
22+
new ItemWithCustomLocator(
23+
ItemConfigV1.builder()
24+
.id(getId(TEST_ITEM_A))
25+
.name(ItemName.of(TEST_API_NAME.get()))
26+
.apiName(TEST_API_NAME)
27+
.spec(ItemConfigV1Spec.native_(NativeItemConfigV1Spec.model(TestModel.of())))
28+
.category(TestCatalog.TEST_CATEGORY_ALPHA)
29+
.creator(TestCatalog.TEST_CREATOR_BETA)
30+
.status(ItemLifecycleStatus.EXPERIMENTAL)
31+
.statusV2(ItemLifecycleStatusV2.experimental(LifecycleStatusExperimental.of()))
32+
.inputSpec(ItemInputSpec.unknownInputType(UnknownInputSpec.of()))
33+
.creationDate(ItemMetadataInfo.builder().build())
34+
.performanceAttributes(
35+
ItemAttributes.builder().build())
36+
.categories(TestCatalog.TEST_CATEGORY_ALPHA)
37+
.build(),
38+
CustomItemLocator.hosted(HostedItemLocator.of(TEST_ITEM_B))),
39+
new ItemWithCustomLocator(
40+
ItemConfigV1.builder()
41+
.id(getId(TestModelCatalog.MODEL_XYZ_123.apiName()))
42+
.name(ItemName.of(TestModelCatalog.MODEL_XYZ_123
43+
.apiName()
44+
.get()))
45+
.apiName(TestModelCatalog.MODEL_XYZ_123.apiName())
46+
.spec(ItemConfigV1Spec.native_(
47+
NativeItemConfigV1Spec.hubModel(HubModelSpec.of())))
48+
.category(TestCatalog.TEST_CATEGORY_ALPHA)
49+
.creator(TestCatalog.TEST_CREATOR_BETA)
50+
.status(ItemLifecycleStatus.EXPERIMENTAL)
51+
.statusV2(ItemLifecycleStatusV2.experimental(LifecycleStatusExperimental.of()))
52+
.inputSpec(ItemInputSpec.unknownInputType(UnknownInputSpec.of()))
53+
.creationDate(ItemMetadataInfo.builder().build())
54+
.performanceAttributes(
55+
ItemAttributes.builder().build())
56+
.categories(TestCatalog.TEST_CATEGORY_ALPHA)
57+
.build(),
58+
CustomItemLocator.hosted(HostedItemLocator.of(TEST_ITEM_C))),
59+
// Discovered items
60+
new ItemWithCustomLocator(
61+
TestModelCatalog.MODEL_ABC_456.toItemApi(),
62+
CustomItemLocator.discovered(DiscoveredItemLocator.of())),
63+
new ItemWithCustomLocator(
64+
ItemConfigV1.builder()
65+
.id(getId(TEST_API_NAME))
66+
.name(ItemName.of(TEST_API_NAME.get()))
67+
.apiName(TEST_API_NAME)
68+
.spec(ItemConfigV1Spec.native_(
69+
NativeItemConfigV1Spec.hubModel(HubModelSpec.of())))
70+
.category(TestCatalog.TEST_CATEGORY_ALPHA)
71+
.creator(TestCatalog.TEST_CREATOR_BETA)
72+
.status(ItemLifecycleStatus.EXPERIMENTAL)
73+
.statusV2(ItemLifecycleStatusV2.experimental(LifecycleStatusExperimental.of()))
74+
.inputSpec(ItemInputSpec.unknownInputType(UnknownInputSpec.of()))
75+
.creationDate(ItemMetadataInfo.builder().build())
76+
.performanceAttributes(
77+
ItemAttributes.builder().build())
78+
.categories(TestCatalog.TEST_CATEGORY_ALPHA)
79+
.build(),
80+
CustomItemLocator.discovered(DiscoveredItemLocator.of()))));
81+
}
1682

17-
void testMethod() {
18-
assertThat(ConfigServiceV1.getAllItems(item1, item2, item3, item4))
19-
.containsExactlyInAnyOrderElementsOf(Set.of(
20-
new ItemWithCustomLocator(
21-
ItemConfigV1.DEFAULT_CONFIG.toCustomString(),
22-
ItemConfigV1.createCustomConfig(
23-
ItemConfigV1Locator.of(TEST_ITEM_A))),
24-
new ItemWithCustomLocator(
25-
ItemConfigV1.builder()
26-
.id(getId(TEST_ITEM_A))
27-
.name(ItemName.of(TEST_API_NAME.get()))
28-
.apiName(TEST_API_NAME)
29-
.spec(ItemConfigV1Spec.native_(
30-
NativeItemConfigV1Spec.model(TestModel.of())))
31-
.category(TestCatalog.TEST_CATEGORY_ALPHA)
32-
.creator(TestCatalog.TEST_CREATOR_BETA)
33-
.status(ItemLifecycleStatus.EXPERIMENTAL)
34-
.statusV2(ItemLifecycleStatusV2.experimental(
35-
LifecycleStatusExperimental.of()))
36-
.inputSpec(ItemInputSpec.unknownInputType(UnknownInputSpec.of()))
37-
.creationDate(
38-
ItemMetadataInfo.builder().build())
39-
.performanceAttributes(
40-
ItemAttributes.builder().build())
41-
.categories(TestCatalog.TEST_CATEGORY_ALPHA)
42-
.build(),
43-
CustomItemLocator.hosted(
44-
HostedItemLocator.of(TEST_ITEM_B))),
45-
new ItemWithCustomLocator(
46-
ItemConfigV1.builder()
47-
.id(getId(TestModelCatalog.MODEL_XYZ_123.apiName()))
48-
.name(ItemName.of(TestModelCatalog.MODEL_XYZ_123
49-
.apiName()
50-
.get()))
51-
.apiName(TestModelCatalog.MODEL_XYZ_123.apiName())
52-
.spec(ItemConfigV1Spec.native_(NativeItemConfigV1Spec.hubModel(
53-
HubModelSpec.of())))
54-
.category(TestCatalog.TEST_CATEGORY_ALPHA)
55-
.creator(TestCatalog.TEST_CREATOR_BETA)
56-
.status(ItemLifecycleStatus.EXPERIMENTAL)
57-
.statusV2(ItemLifecycleStatusV2.experimental(
58-
LifecycleStatusExperimental.of()))
59-
.inputSpec(ItemInputSpec.unknownInputType(UnknownInputSpec.of()))
60-
.creationDate(
61-
ItemMetadataInfo.builder().build())
62-
.performanceAttributes(
63-
ItemAttributes.builder().build())
64-
.categories(TestCatalog.TEST_CATEGORY_ALPHA)
65-
.build(),
66-
CustomItemLocator.hosted(
67-
HostedItemLocator.of(TEST_ITEM_C))),
68-
// Discovered items
69-
new ItemWithCustomLocator(
70-
TestModelCatalog.MODEL_ABC_456.toItemApi(),
71-
CustomItemLocator.discovered(DiscoveredItemLocator.of())),
72-
new ItemWithCustomLocator(
73-
ItemConfigV1.builder()
74-
.id(getId(TEST_API_NAME))
75-
.name(ItemName.of(TEST_API_NAME.get()))
76-
.apiName(TEST_API_NAME)
77-
.spec(ItemConfigV1Spec.native_(NativeItemConfigV1Spec.hubModel(
78-
HubModelSpec.of())))
79-
.category(TestCatalog.TEST_CATEGORY_ALPHA)
80-
.creator(TestCatalog.TEST_CREATOR_BETA)
81-
.status(ItemLifecycleStatus.EXPERIMENTAL)
82-
.statusV2(ItemLifecycleStatusV2.experimental(
83-
LifecycleStatusExperimental.of()))
84-
.inputSpec(ItemInputSpec.unknownInputType(UnknownInputSpec.of()))
85-
.creationDate(
86-
ItemMetadataInfo.builder().build())
87-
.performanceAttributes(
88-
ItemAttributes.builder().build())
89-
.categories(TestCatalog.TEST_CATEGORY_ALPHA)
90-
.build(),
91-
CustomItemLocator.discovered(DiscoveredItemLocator.of()))));
92-
}
93-
94-
public Map<FooBarRid, BazQuxMetrics> otherMethod(
95-
FooAuthHeader authHeader, Set<FooBarRid> thingRids, WidgetTimeRange timeRange) {
96-
return myCustomService
97-
.get()
98-
.fetchData(authHeader, FooMyCustomClass.of(thingRids, timeRange))
99-
.entrySet()
100-
.stream()
101-
.collect(Collectors.toMap(
102-
Map.Entry::getKey, entry -> entry.getValue().getMetrics()));
103-
}
104-
}
83+
public Map<FooBarRid, BazQuxMetrics> otherMethod(
84+
FooAuthHeader authHeader, Set<FooBarRid> thingRids, WidgetTimeRange timeRange) {
85+
return myCustomService
86+
.get()
87+
.fetchData(authHeader, FooMyCustomClass.of(thingRids, timeRange))
88+
.entrySet()
89+
.stream()
90+
.collect(Collectors.toMap(
91+
Map.Entry::getKey, entry -> entry.getValue().getMetrics()));
92+
}
93+
}

0 commit comments

Comments
 (0)