Skip to content

Inline stage 1 #53

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 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,20 @@ jmh {
jvmArgsPrepend = [
'--add-modules=jdk.incubator.vector'
]
if (getBooleanProperty('jmh.profilersEnabled', false)) {
createDirIfDoesNotExist('./profilers')
if (OperatingSystem.current().isLinux()) {
def profilerList = [
'async:verbose=true;output=flamegraph;event=cpu;dir=./profilers/async;libPath=' + getLibPath('LD_LIBRARY_PATH')
]
if (getBooleanProperty('jmh.jitLogEnabled', false)) {
createDirIfDoesNotExist('./profilers/perfasm')
profilerList += [
'perfasm:intelSyntax=true;saveLog=true;saveLogTo=./profilers/perfasm'
]
}
profilers = profilerList
} else if (OperatingSystem.current().isMacOsX()) {
profilers = [
'async:verbose=true;output=flamegraph;event=cpu;dir=./profilers/async;libPath=' + getLibPath('DYLD_LIBRARY_PATH')
]
if (OperatingSystem.current().isLinux()) {
def profilerList = []
if (getBooleanProperty('jmh.asyncProfilerEnabled', false)) {
createDirIfDoesNotExist('./profilers/async')
profilerList += ['async:verbose=true;output=flamegraph;event=cpu;dir=./profilers/async;libPath=' + getLibPath('LD_LIBRARY_PATH')]
}
if (getBooleanProperty('jmh.perfAsmEnabled', false)) {
createDirIfDoesNotExist('./profilers/perfasm')
profilerList += ['perfasm:intelSyntax=true;saveLog=true;saveLogTo=./profilers/perfasm']
}
if (getBooleanProperty('jmh.perfEnabled', false)) {
profilerList += ['perf']
}
profilers = profilerList
}
if (project.hasProperty('jmh.includes')) {
includes = [project.findProperty('jmh.includes')]
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/org/simdjson/ParseAndSelectBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void setup() throws IOException {
buffer = is.readAllBytes();
bufferPadded = padded(buffer);
}
System.out.println("VectorSpecies = " + StructuralIndexer.BYTE_SPECIES);
System.out.println("VectorSpecies = " + VectorUtils.BYTE_SPECIES);
}

@Benchmark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void setup() throws IOException {
buffer = is.readAllBytes();
bufferPadded = padded(buffer);
}
System.out.println("VectorSpecies = " + StructuralIndexer.BYTE_SPECIES);
System.out.println("VectorSpecies = " + VectorUtils.BYTE_SPECIES);
}

@Benchmark
Expand Down
13 changes: 11 additions & 2 deletions src/jmh/java/org/simdjson/Utf8ValidatorBenchmark.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package org.simdjson;

import com.google.common.base.Utf8;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -11,6 +19,7 @@
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
public class Utf8ValidatorBenchmark {

@Param({"/twitter.json", "/gsoc-2018.json", "/github_events.json"})
String fileName;
byte[] bytes;
Expand All @@ -24,7 +33,7 @@ public void setup() throws IOException {

@Benchmark
public void utf8Validator() {
Utf8Validator.validate(bytes);
Utf8Validator.validate(bytes, bytes.length);
}

@Benchmark
Expand Down
49 changes: 0 additions & 49 deletions src/main/java/org/simdjson/BlockReader.java

This file was deleted.

66 changes: 0 additions & 66 deletions src/main/java/org/simdjson/CharactersClassifier.java

This file was deleted.

8 changes: 0 additions & 8 deletions src/main/java/org/simdjson/JsonCharacterBlock.java

This file was deleted.

12 changes: 0 additions & 12 deletions src/main/java/org/simdjson/JsonStringBlock.java

This file was deleted.

90 changes: 0 additions & 90 deletions src/main/java/org/simdjson/JsonStringScanner.java

This file was deleted.

33 changes: 8 additions & 25 deletions src/main/java/org/simdjson/SimdJsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

public class SimdJsonParser {

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

private final BlockReader reader;
private final StructuralIndexer indexer;
private final BitIndexes bitIndexes;
private final JsonIterator jsonIterator;
Expand All @@ -24,23 +22,20 @@ public SimdJsonParser(int capacity, int maxDepth) {
jsonIterator = new JsonIterator(bitIndexes, stringBuffer, capacity, maxDepth, PADDING);
schemaBasedJsonIterator = new SchemaBasedJsonIterator(bitIndexes, stringBuffer, PADDING);
paddedBuffer = new byte[capacity];
reader = new BlockReader(STEP_SIZE);
indexer = new StructuralIndexer(bitIndexes);
}

public <T> T parse(byte[] buffer, int len, Class<T> expectedType) {
stage0(buffer);
byte[] padded = padIfNeeded(buffer, len);
reset(padded, len);
stage1(padded);
reset();
stage1(padded, len);
return schemaBasedJsonIterator.walkDocument(padded, len, expectedType);
}

public JsonValue parse(byte[] buffer, int len) {
stage0(buffer);
byte[] padded = padIfNeeded(buffer, len);
reset(padded, len);
stage1(padded);
reset();
stage1(padded, len);
return jsonIterator.walkDocument(padded, len);
}

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

private void reset(byte[] buffer, int len) {
indexer.reset();
reader.reset(buffer, len);
private void reset() {
bitIndexes.reset();
jsonIterator.reset();
}

private void stage0(byte[] buffer) {
Utf8Validator.validate(buffer);
}

private void stage1(byte[] buffer) {
while (reader.hasFullBlock()) {
int blockIndex = reader.getBlockIndex();
indexer.step(buffer, blockIndex, blockIndex);
reader.advance();
}
indexer.step(reader.remainder(), 0, reader.getBlockIndex());
reader.advance();
indexer.finish(reader.getBlockIndex());
private void stage1(byte[] buffer, int length) {
Utf8Validator.validate(buffer, length);
indexer.index(buffer, length);
}
}
Loading