Skip to content

Commit b40426e

Browse files
laurentgokou
authored andcommitted
GH-40830: [Java] Adding Spotless to Performance module (#42057)
### Rationale for this change Applying Java code style and formatting options to Performance module. ### What changes are included in this PR? Java code formatting via spotless plugin has been enabled. ### Are these changes tested? Yes, but doesn't involve test cases, the plugin itself corrects. ### Are there any user-facing changes? No * GitHub Issue: #40830 Authored-by: Laurent Goujon <laurent@apache.org> Signed-off-by: David Li <li.davidm96@gmail.com>
1 parent 8afa035 commit b40426e

22 files changed

Lines changed: 205 additions & 363 deletions

performance/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ under the License.
3030
<description>JMH Performance benchmarks for other Arrow libraries.</description>
3131

3232
<properties>
33+
<checkstyle.config.location>dev/checkstyle/checkstyle-spotless.xml</checkstyle.config.location>
34+
<spotless.java.excludes>none</spotless.java.excludes>
3335
<jmh.version>1.37</jmh.version>
3436
<uberjar.name>benchmarks</uberjar.name>
3537
<skip.perf.benchmarks>true</skip.perf.benchmarks>

performance/src/main/java/org/apache/arrow/adapter/AvroAdapterBenchmarks.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
package org.apache.arrow.adapter;
1918

2019
import java.io.ByteArrayInputStream;
2120
import java.io.ByteArrayOutputStream;
2221
import java.util.concurrent.TimeUnit;
23-
2422
import org.apache.arrow.adapter.avro.AvroToArrow;
2523
import org.apache.arrow.adapter.avro.AvroToArrowConfig;
2624
import org.apache.arrow.adapter.avro.AvroToArrowConfigBuilder;
@@ -52,9 +50,7 @@
5250
import org.openjdk.jmh.runner.options.Options;
5351
import org.openjdk.jmh.runner.options.OptionsBuilder;
5452

55-
/**
56-
* Benchmarks for avro adapter.
57-
*/
53+
/** Benchmarks for avro adapter. */
5854
@State(Scope.Benchmark)
5955
public class AvroAdapterBenchmarks {
6056

@@ -65,21 +61,25 @@ public class AvroAdapterBenchmarks {
6561
private Schema schema;
6662
private BinaryDecoder decoder;
6763

68-
/**
69-
* Setup benchmarks.
70-
*/
64+
/** Setup benchmarks. */
7165
@Setup
7266
public void prepare() throws Exception {
7367
BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE);
7468
config = new AvroToArrowConfigBuilder(allocator).build();
7569

76-
String schemaStr = "{\n" + " \"namespace\": \"org.apache.arrow.avro\",\n" +
77-
" \"type\": \"record\",\n" + " \"name\": \"testBenchmark\",\n" + " \"fields\": [\n" +
78-
" {\"name\": \"f0\", \"type\": \"string\"},\n" +
79-
" {\"name\": \"f1\", \"type\": \"int\"},\n" +
80-
" {\"name\": \"f2\", \"type\": \"long\"},\n" +
81-
" {\"name\": \"f3\", \"type\": \"boolean\"},\n" +
82-
" {\"name\": \"f4\", \"type\": \"float\"}\n" + " ]\n" + "}";
70+
String schemaStr =
71+
"{\n"
72+
+ " \"namespace\": \"org.apache.arrow.avro\",\n"
73+
+ " \"type\": \"record\",\n"
74+
+ " \"name\": \"testBenchmark\",\n"
75+
+ " \"fields\": [\n"
76+
+ " {\"name\": \"f0\", \"type\": \"string\"},\n"
77+
+ " {\"name\": \"f1\", \"type\": \"int\"},\n"
78+
+ " {\"name\": \"f2\", \"type\": \"long\"},\n"
79+
+ " {\"name\": \"f3\", \"type\": \"boolean\"},\n"
80+
+ " {\"name\": \"f4\", \"type\": \"float\"}\n"
81+
+ " ]\n"
82+
+ "}";
8383
schema = new Schema.Parser().parse(schemaStr);
8484

8585
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -96,19 +96,19 @@ public void prepare() throws Exception {
9696
writer.write(record, encoder);
9797
}
9898

99-
decoder = new DecoderFactory().directBinaryDecoder(new ByteArrayInputStream(out.toByteArray()), null);
99+
decoder =
100+
new DecoderFactory().directBinaryDecoder(new ByteArrayInputStream(out.toByteArray()), null);
100101
}
101102

102-
/**
103-
* Tear down benchmarks.
104-
*/
103+
/** Tear down benchmarks. */
105104
@TearDown
106105
public void tearDown() {
107106
config.getAllocator().close();
108107
}
109108

110109
/**
111110
* Test {@link AvroToArrow#avroToArrowIterator(Schema, Decoder, AvroToArrowConfig)}.
111+
*
112112
* @return useless. To avoid DCE by JIT.
113113
*/
114114
@Benchmark
@@ -117,7 +117,8 @@ public void tearDown() {
117117
public int testAvroToArrow() throws Exception {
118118
decoder.inputStream().reset();
119119
int sum = 0;
120-
try (AvroToArrowVectorIterator iter = AvroToArrow.avroToArrowIterator(schema, decoder, config)) {
120+
try (AvroToArrowVectorIterator iter =
121+
AvroToArrow.avroToArrowIterator(schema, decoder, config)) {
121122
while (iter.hasNext()) {
122123
VectorSchemaRoot root = iter.next();
123124
IntVector intVector = (IntVector) root.getVector("f1");
@@ -131,10 +132,8 @@ public int testAvroToArrow() throws Exception {
131132
}
132133

133134
public static void main(String[] args) throws RunnerException {
134-
Options opt = new OptionsBuilder()
135-
.include(AvroAdapterBenchmarks.class.getSimpleName())
136-
.forks(1)
137-
.build();
135+
Options opt =
136+
new OptionsBuilder().include(AvroAdapterBenchmarks.class.getSimpleName()).forks(1).build();
138137

139138
new Runner(opt).run();
140139
}

performance/src/main/java/org/apache/arrow/adapter/jdbc/JdbcAdapterBenchmarks.java

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
package org.apache.arrow.adapter.jdbc;
1918

2019
import java.sql.Connection;
@@ -23,7 +22,6 @@
2322
import java.sql.ResultSet;
2423
import java.sql.Statement;
2524
import java.util.concurrent.TimeUnit;
26-
2725
import org.apache.arrow.adapter.jdbc.consumer.BigIntConsumer;
2826
import org.apache.arrow.adapter.jdbc.consumer.BitConsumer;
2927
import org.apache.arrow.adapter.jdbc.consumer.IntConsumer;
@@ -50,27 +48,23 @@
5048
import org.openjdk.jmh.runner.options.Options;
5149
import org.openjdk.jmh.runner.options.OptionsBuilder;
5250

53-
/**
54-
* Benchmarks for Jdbc adapter.
55-
*/
51+
/** Benchmarks for Jdbc adapter. */
5652
public class JdbcAdapterBenchmarks {
5753
// checkstyle:off: MissingJavadocMethod
5854

5955
private static final int VALUE_COUNT = 3000;
6056

6157
private static final String CREATE_STATEMENT =
62-
"CREATE TABLE test_table (f0 INT, f1 LONG, f2 VARCHAR, f3 BOOLEAN);";
58+
"CREATE TABLE test_table (f0 INT, f1 LONG, f2 VARCHAR, f3 BOOLEAN);";
6359
private static final String INSERT_STATEMENT =
64-
"INSERT INTO test_table (f0, f1, f2, f3) VALUES (?, ?, ?, ?);";
60+
"INSERT INTO test_table (f0, f1, f2, f3) VALUES (?, ?, ?, ?);";
6561
private static final String QUERY = "SELECT f0, f1, f2, f3 FROM test_table;";
6662
private static final String DROP_STATEMENT = "DROP TABLE test_table;";
6763

6864
private static final String URL = "jdbc:h2:mem:JdbcAdapterBenchmarks";
6965
private static final String DRIVER = "org.h2.Driver";
7066

71-
/**
72-
* State object for the jdbc e2e benchmark.
73-
*/
67+
/** State object for the jdbc e2e benchmark. */
7468
@State(Scope.Benchmark)
7569
public static class JdbcState {
7670

@@ -87,7 +81,8 @@ public static class JdbcState {
8781
@Setup(Level.Trial)
8882
public void prepareState() throws Exception {
8983
allocator = new RootAllocator(Integer.MAX_VALUE);
90-
config = new JdbcToArrowConfigBuilder().setAllocator(allocator).setTargetBatchSize(1024).build();
84+
config =
85+
new JdbcToArrowConfigBuilder().setAllocator(allocator).setTargetBatchSize(1024).build();
9186
Class.forName(DRIVER);
9287
conn = DriverManager.getConnection(URL);
9388

@@ -129,9 +124,7 @@ public void tearDownState() throws Exception {
129124
}
130125
}
131126

132-
/**
133-
* State object for the consume benchmark.
134-
*/
127+
/** State object for the consume benchmark. */
135128
@State(Scope.Benchmark)
136129
public static class ConsumeState {
137130

@@ -166,7 +159,8 @@ public static class ConsumeState {
166159
@Setup(Level.Trial)
167160
public void prepare() throws Exception {
168161
allocator = new RootAllocator(Integer.MAX_VALUE);
169-
config = new JdbcToArrowConfigBuilder().setAllocator(allocator).setTargetBatchSize(1024).build();
162+
config =
163+
new JdbcToArrowConfigBuilder().setAllocator(allocator).setTargetBatchSize(1024).build();
170164

171165
Class.forName(DRIVER);
172166
conn = DriverManager.getConnection(URL);
@@ -233,9 +227,7 @@ public void tearDown() throws Exception {
233227
}
234228
}
235229

236-
/**
237-
* State object for the jdbc row consume benchmark.
238-
*/
230+
/** State object for the jdbc row consume benchmark. */
239231
@State(Scope.Benchmark)
240232
public static class RowConsumeState {
241233

@@ -256,7 +248,11 @@ public static class RowConsumeState {
256248
@Setup(Level.Trial)
257249
public void prepareState() throws Exception {
258250
allocator = new RootAllocator(Integer.MAX_VALUE);
259-
config = new JdbcToArrowConfigBuilder().setAllocator(allocator).setTargetBatchSize(VALUE_COUNT).build();
251+
config =
252+
new JdbcToArrowConfigBuilder()
253+
.setAllocator(allocator)
254+
.setTargetBatchSize(VALUE_COUNT)
255+
.build();
260256
Class.forName(DRIVER);
261257
conn = DriverManager.getConnection(URL);
262258

@@ -305,14 +301,16 @@ public void tearDownState() throws Exception {
305301

306302
/**
307303
* Test {@link JdbcToArrow#sqlToArrowVectorIterator(ResultSet, JdbcToArrowConfig)}.
304+
*
308305
* @return useless. To avoid DCE by JIT.
309306
*/
310307
@Benchmark
311308
@BenchmarkMode(Mode.AverageTime)
312309
@OutputTimeUnit(TimeUnit.MICROSECONDS)
313310
public int testJdbcToArrow(JdbcState state) throws Exception {
314311
int valueCount = 0;
315-
try (ArrowVectorIterator iter = JdbcToArrow.sqlToArrowVectorIterator(state.resultSet, state.config)) {
312+
try (ArrowVectorIterator iter =
313+
JdbcToArrow.sqlToArrowVectorIterator(state.resultSet, state.config)) {
316314
while (iter.hasNext()) {
317315
VectorSchemaRoot root = iter.next();
318316
IntVector intVector = (IntVector) root.getFieldVectors().get(0);
@@ -349,13 +347,10 @@ public void consumeRowsBenchmark(RowConsumeState state) throws Exception {
349347
}
350348

351349
public static void main(String[] args) throws RunnerException {
352-
Options opt = new OptionsBuilder()
353-
.include(JdbcAdapterBenchmarks.class.getSimpleName())
354-
.forks(1)
355-
.build();
350+
Options opt =
351+
new OptionsBuilder().include(JdbcAdapterBenchmarks.class.getSimpleName()).forks(1).build();
356352

357353
new Runner(opt).run();
358354
}
359355
// checkstyle:on: MissingJavadocMethod
360356
}
361-

performance/src/main/java/org/apache/arrow/algorithm/search/ParallelSearcherBenchmarks.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
package org.apache.arrow.algorithm.search;
1918

2019
import java.util.concurrent.ExecutorService;
2120
import java.util.concurrent.Executors;
2221
import java.util.concurrent.TimeUnit;
23-
2422
import org.apache.arrow.memory.BufferAllocator;
2523
import org.apache.arrow.memory.RootAllocator;
2624
import org.apache.arrow.vector.IntVector;
@@ -39,17 +37,13 @@
3937
import org.openjdk.jmh.runner.options.Options;
4038
import org.openjdk.jmh.runner.options.OptionsBuilder;
4139

42-
/**
43-
* Benchmarks for {@link ParallelSearcher}.
44-
*/
40+
/** Benchmarks for {@link ParallelSearcher}. */
4541
public class ParallelSearcherBenchmarks {
4642
// checkstyle:off: MissingJavadocMethod
4743

4844
private static final int VECTOR_LENGTH = 1024 * 1024;
4945

50-
/**
51-
* State object for the benchmarks.
52-
*/
46+
/** State object for the benchmarks. */
5347
@State(Scope.Benchmark)
5448
public static class SearchState {
5549

@@ -106,7 +100,8 @@ public void searchBenchmark(SearchState state) throws Exception {
106100
}
107101

108102
public static void main(String[] args) throws RunnerException {
109-
Options opt = new OptionsBuilder()
103+
Options opt =
104+
new OptionsBuilder()
110105
.include(ParallelSearcherBenchmarks.class.getSimpleName())
111106
.forks(1)
112107
.build();

performance/src/main/java/org/apache/arrow/memory/AllocatorBenchmarks.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
package org.apache.arrow.memory;
1918

2019
import java.util.concurrent.TimeUnit;
21-
22-
import org.apache.arrow.memory.ArrowBuf;
2320
import org.apache.arrow.memory.rounding.RoundingPolicy;
2421
import org.apache.arrow.memory.rounding.SegmentRoundingPolicy;
2522
import org.openjdk.jmh.annotations.Benchmark;
@@ -31,14 +28,10 @@
3128
import org.openjdk.jmh.runner.options.Options;
3229
import org.openjdk.jmh.runner.options.OptionsBuilder;
3330

34-
/**
35-
* Benchmarks for allocators.
36-
*/
31+
/** Benchmarks for allocators. */
3732
public class AllocatorBenchmarks {
3833

39-
/**
40-
* Benchmark for the default allocator.
41-
*/
34+
/** Benchmark for the default allocator. */
4235
@Benchmark
4336
@BenchmarkMode(Mode.AverageTime)
4437
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@@ -59,9 +52,7 @@ public void defaultAllocatorBenchmark() {
5952
}
6053
}
6154

62-
/**
63-
* Benchmark for allocator with segment rounding policy.
64-
*/
55+
/** Benchmark for allocator with segment rounding policy. */
6556
@Benchmark
6657
@BenchmarkMode(Mode.AverageTime)
6758
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@@ -71,7 +62,8 @@ public void segmentRoundingPolicyBenchmark() {
7162
final int segmentSize = 1024;
7263

7364
RoundingPolicy policy = new SegmentRoundingPolicy(segmentSize);
74-
try (RootAllocator allocator = new RootAllocator(AllocationListener.NOOP, bufferSize * numBuffers, policy)) {
65+
try (RootAllocator allocator =
66+
new RootAllocator(AllocationListener.NOOP, bufferSize * numBuffers, policy)) {
7567
ArrowBuf[] buffers = new ArrowBuf[numBuffers];
7668

7769
for (int i = 0; i < numBuffers; i++) {
@@ -85,10 +77,8 @@ public void segmentRoundingPolicyBenchmark() {
8577
}
8678

8779
public static void main(String[] args) throws RunnerException {
88-
Options opt = new OptionsBuilder()
89-
.include(AllocatorBenchmarks.class.getSimpleName())
90-
.forks(1)
91-
.build();
80+
Options opt =
81+
new OptionsBuilder().include(AllocatorBenchmarks.class.getSimpleName()).forks(1).build();
9282

9383
new Runner(opt).run();
9484
}

0 commit comments

Comments
 (0)