Skip to content

Commit ffc7f14

Browse files
authored
Inline stage 1 (#53)
1 parent d8a3ef6 commit ffc7f14

36 files changed

+1444
-1447
lines changed

build.gradle

+13-17
Original file line numberDiff line numberDiff line change
@@ -136,24 +136,20 @@ jmh {
136136
jvmArgsPrepend = [
137137
'--add-modules=jdk.incubator.vector'
138138
]
139-
if (getBooleanProperty('jmh.profilersEnabled', false)) {
140-
createDirIfDoesNotExist('./profilers')
141-
if (OperatingSystem.current().isLinux()) {
142-
def profilerList = [
143-
'async:verbose=true;output=flamegraph;event=cpu;dir=./profilers/async;libPath=' + getLibPath('LD_LIBRARY_PATH')
144-
]
145-
if (getBooleanProperty('jmh.jitLogEnabled', false)) {
146-
createDirIfDoesNotExist('./profilers/perfasm')
147-
profilerList += [
148-
'perfasm:intelSyntax=true;saveLog=true;saveLogTo=./profilers/perfasm'
149-
]
150-
}
151-
profilers = profilerList
152-
} else if (OperatingSystem.current().isMacOsX()) {
153-
profilers = [
154-
'async:verbose=true;output=flamegraph;event=cpu;dir=./profilers/async;libPath=' + getLibPath('DYLD_LIBRARY_PATH')
155-
]
139+
if (OperatingSystem.current().isLinux()) {
140+
def profilerList = []
141+
if (getBooleanProperty('jmh.asyncProfilerEnabled', false)) {
142+
createDirIfDoesNotExist('./profilers/async')
143+
profilerList += ['async:verbose=true;output=flamegraph;event=cpu;dir=./profilers/async;libPath=' + getLibPath('LD_LIBRARY_PATH')]
144+
}
145+
if (getBooleanProperty('jmh.perfAsmEnabled', false)) {
146+
createDirIfDoesNotExist('./profilers/perfasm')
147+
profilerList += ['perfasm:intelSyntax=true;saveLog=true;saveLogTo=./profilers/perfasm']
148+
}
149+
if (getBooleanProperty('jmh.perfEnabled', false)) {
150+
profilerList += ['perf']
156151
}
152+
profilers = profilerList
157153
}
158154
if (project.hasProperty('jmh.includes')) {
159155
includes = [project.findProperty('jmh.includes')]

src/jmh/java/org/simdjson/ParseAndSelectBenchmark.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void setup() throws IOException {
3939
buffer = is.readAllBytes();
4040
bufferPadded = padded(buffer);
4141
}
42-
System.out.println("VectorSpecies = " + StructuralIndexer.BYTE_SPECIES);
42+
System.out.println("VectorSpecies = " + VectorUtils.BYTE_SPECIES);
4343
}
4444

4545
@Benchmark

src/jmh/java/org/simdjson/SchemaBasedParseAndSelectBenchmark.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void setup() throws IOException {
4141
buffer = is.readAllBytes();
4242
bufferPadded = padded(buffer);
4343
}
44-
System.out.println("VectorSpecies = " + StructuralIndexer.BYTE_SPECIES);
44+
System.out.println("VectorSpecies = " + VectorUtils.BYTE_SPECIES);
4545
}
4646

4747
@Benchmark

src/jmh/java/org/simdjson/Utf8ValidatorBenchmark.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package org.simdjson;
22

33
import com.google.common.base.Utf8;
4-
import org.openjdk.jmh.annotations.*;
4+
import org.openjdk.jmh.annotations.Benchmark;
5+
import org.openjdk.jmh.annotations.BenchmarkMode;
6+
import org.openjdk.jmh.annotations.Level;
7+
import org.openjdk.jmh.annotations.Mode;
8+
import org.openjdk.jmh.annotations.OutputTimeUnit;
9+
import org.openjdk.jmh.annotations.Param;
10+
import org.openjdk.jmh.annotations.Scope;
11+
import org.openjdk.jmh.annotations.Setup;
12+
import org.openjdk.jmh.annotations.State;
513

614
import java.io.IOException;
715
import java.io.InputStream;
@@ -11,6 +19,7 @@
1119
@BenchmarkMode(Mode.Throughput)
1220
@OutputTimeUnit(TimeUnit.SECONDS)
1321
public class Utf8ValidatorBenchmark {
22+
1423
@Param({"/twitter.json", "/gsoc-2018.json", "/github_events.json"})
1524
String fileName;
1625
byte[] bytes;
@@ -24,7 +33,7 @@ public void setup() throws IOException {
2433

2534
@Benchmark
2635
public void utf8Validator() {
27-
Utf8Validator.validate(bytes);
36+
Utf8Validator.validate(bytes, bytes.length);
2837
}
2938

3039
@Benchmark

src/main/java/org/simdjson/BlockReader.java

-49
This file was deleted.

src/main/java/org/simdjson/CharactersClassifier.java

-66
This file was deleted.

src/main/java/org/simdjson/JsonCharacterBlock.java

-8
This file was deleted.

src/main/java/org/simdjson/JsonStringBlock.java

-12
This file was deleted.

src/main/java/org/simdjson/JsonStringScanner.java

-90
This file was deleted.

src/main/java/org/simdjson/SimdJsonParser.java

+8-25
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
public class SimdJsonParser {
44

5-
private static final int STEP_SIZE = 64;
65
private static final int PADDING = 64;
76
private static final int DEFAULT_CAPACITY = 34 * 1024 * 1024; // we should be able to handle jsons <= 34MiB
87
private static final int DEFAULT_MAX_DEPTH = 1024;
98

10-
private final BlockReader reader;
119
private final StructuralIndexer indexer;
1210
private final BitIndexes bitIndexes;
1311
private final JsonIterator jsonIterator;
@@ -24,23 +22,20 @@ public SimdJsonParser(int capacity, int maxDepth) {
2422
jsonIterator = new JsonIterator(bitIndexes, stringBuffer, capacity, maxDepth, PADDING);
2523
schemaBasedJsonIterator = new SchemaBasedJsonIterator(bitIndexes, stringBuffer, PADDING);
2624
paddedBuffer = new byte[capacity];
27-
reader = new BlockReader(STEP_SIZE);
2825
indexer = new StructuralIndexer(bitIndexes);
2926
}
3027

3128
public <T> T parse(byte[] buffer, int len, Class<T> expectedType) {
32-
stage0(buffer);
3329
byte[] padded = padIfNeeded(buffer, len);
34-
reset(padded, len);
35-
stage1(padded);
30+
reset();
31+
stage1(padded, len);
3632
return schemaBasedJsonIterator.walkDocument(padded, len, expectedType);
3733
}
3834

3935
public JsonValue parse(byte[] buffer, int len) {
40-
stage0(buffer);
4136
byte[] padded = padIfNeeded(buffer, len);
42-
reset(padded, len);
43-
stage1(padded);
37+
reset();
38+
stage1(padded, len);
4439
return jsonIterator.walkDocument(padded, len);
4540
}
4641

@@ -52,25 +47,13 @@ private byte[] padIfNeeded(byte[] buffer, int len) {
5247
return buffer;
5348
}
5449

55-
private void reset(byte[] buffer, int len) {
56-
indexer.reset();
57-
reader.reset(buffer, len);
50+
private void reset() {
5851
bitIndexes.reset();
5952
jsonIterator.reset();
6053
}
6154

62-
private void stage0(byte[] buffer) {
63-
Utf8Validator.validate(buffer);
64-
}
65-
66-
private void stage1(byte[] buffer) {
67-
while (reader.hasFullBlock()) {
68-
int blockIndex = reader.getBlockIndex();
69-
indexer.step(buffer, blockIndex, blockIndex);
70-
reader.advance();
71-
}
72-
indexer.step(reader.remainder(), 0, reader.getBlockIndex());
73-
reader.advance();
74-
indexer.finish(reader.getBlockIndex());
55+
private void stage1(byte[] buffer, int length) {
56+
Utf8Validator.validate(buffer, length);
57+
indexer.index(buffer, length);
7558
}
7659
}

0 commit comments

Comments
 (0)