Skip to content

Commit

Permalink
New JSON parsing API with significant performance optimizations (#72)
Browse files Browse the repository at this point in the history
* optimize json parsing...

especially when "type" is not encountered first during parsing

* major optimization to slow path in json parse

* use IllegalStateException instead of JsonIOException

* add method ABIJSON.optimizeJson(String)

* inline

* minor refactor

* JsonSpliterator refactors

* set JsonReader nesting limit at 50;

simplify reflect-config;

* add comments

* fix functions with no type field can't be filtered out in array parse

* add ABIJSON convenience methods;

parseArray now handles IOException itself;

* improve test

* complete merge of master into this branch

* eliminate some convenience methods

* add class ABIParser;

remove some ABIJSON methods;
remove json test file;

* improve error message

* add comment; code cleanup;

* parseArray refactoring

* improve json minimization

* improve test; update workflow;

* FLAG_LEGACY_DECODE no longer labeled experimental

* JsonSpliterator refactoring

* JsonSpliterator refactoring

clean up test;

* update commons-codec

* clean up unnecessary conditional

* eliminate redundant null check

* improve metaTest1 reliability

* code cleanup in tests

* improve error behavior for missing type field

* throw on unexpected components field

* improve tupletype json validation

* improve test

* improve error behavior of json parser

* improve error message

* parseTupleType refactoring

* reorder error checks

* disallow chars after "tuple" and before array suffix

* minor refactor

* add javadoc comment

* update performance note
  • Loading branch information
esaulpaugh authored Feb 9, 2025
1 parent 46a9d51 commit 93c93ea
Show file tree
Hide file tree
Showing 18 changed files with 680 additions and 342 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/alt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:

strategy:
matrix:
os: [ windows-2022, windows-2025, ubuntu-24.04 ]
os: [ windows-2025, ubuntu-24.04 ]
version: [ '23' ]
distribution: [ 'graalvm' ]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Also includes optimized implementations of:

headlong depends on gson v2.1 or greater at runtime and v2.11.0 or greater at compile time. Test suite should take less than one minute to run. Test packages require junit. Jar size is ~128 KiB. Java 8+.

For best JSON parsing performance, make sure objects are compact and that the "type" field is positioned first. See ABIJSON.tryParseStreaming. This can be done via the method `Function#toJson(boolean)` while giving `false` as the argument (no pretty print).
For better contract ABI JSON parsing performance, consider ABIJSON methods which accept a `Set<TypeEnum>` by which to filter objects by type. For best performance, json should be compact and "type" should be the first key in functions, events, and errors. This can be done via `ABIJSON.optimizeJson(String)`.

See the wiki for more, such as packed encoding (and decoding) and RLP Object Notation: https://github.com/esaulpaugh/headlong/wiki

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ dependencies {
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.11.4")
testImplementation("org.bouncycastle:bcprov-jdk14:" + bcVersion)

jmhImplementation("commons-codec:commons-codec:1.17.2")
jmhImplementation("commons-codec:commons-codec:1.18.0")
jmhImplementation("org.openjdk.jmh:jmh-core:" + jmhVersion)
jmhAnnotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:" + jmhVersion)
jmhImplementation("org.bouncycastle:bcprov-jdk14:" + bcVersion)
Expand Down
22 changes: 0 additions & 22 deletions graal-config/reflect-config.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
[
{
"name": "com.google.gson.stream.JsonReader",
"methods": [
{
"name": "setStrictness",
"parameterTypes": ["com.google.gson.Strictness"]
}
]
},
{
"name": "com.google.gson.Strictness",
"methods": [
{
"name": "valueOf",
"parameterTypes": ["java.lang.String"]
},
{
"name": "valueOf",
"parameterTypes": [ "java.lang.Class" ,"java.lang.String"]
}
]
},
{
"name" : "byte[]",
"unsafeAllocated" : true
Expand Down
20 changes: 10 additions & 10 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,15 @@
</artifact>
</component>

<component group="commons-codec" name="commons-codec" version="1.17.2">
<artifact name="commons-codec-1.17.2.jar">
<sha256 value="4148332728490cef12b29dac4c385f46982f04285132c6fa51ad7267d7dc7a8b" origin="repo.maven.apache.org/maven2/"/>
<component group="commons-codec" name="commons-codec" version="1.18.0">
<artifact name="commons-codec-1.18.0.jar">
<sha256 value="ba005f304cef92a3dede24a38ad5ac9b8afccf0d8f75839d6c1338634cf7f6e4" origin="repo.maven.apache.org/maven2/"/>
</artifact>
<artifact name="commons-codec-1.17.2.pom">
<sha256 value="e2402fb9a6060384f32bd4fc6902b106bff7afc7b9529b831a850cacaaa3246e" origin="repo.maven.apache.org/maven2/"/>
<artifact name="commons-codec-1.18.0.pom">
<sha256 value="74b916da4b0384c619e6dd4c18defe8aa4387f795205253cfb4bbb2f458cddce" origin="repo.maven.apache.org/maven2/"/>
</artifact>
<artifact name="commons-codec-1.17.2-sources.jar">
<sha256 value="6cfa7935df61d05e4cfd92d0f141d91a368c6847be1febb8a5fcf211bde4c4f1" origin="repo.maven.apache.org/maven2/"/>
<artifact name="commons-codec-1.18.0-sources.jar">
<sha256 value="6c50e3dd81284139baddf94b3d0f78d25135eea0853f6495267196cdcf5949e3" origin="repo.maven.apache.org/maven2/"/>
</artifact>
</component>
<component group="org.ow2.asm" name="asm" version="9.0">
Expand Down Expand Up @@ -341,9 +341,9 @@
<sha256 value="87cd27e1a02a5c3eb6d85059ce98696bb1b44c2b8b650f0567c86df60fa61da7" origin="repo.maven.apache.org/maven2/"/>
</artifact>
</component>
<component group="org.apache.commons" name="commons-parent" version="78">
<artifact name="commons-parent-78.pom">
<sha256 value="022d202e655edd04f2a10ecbe453d92977924d38380a4ca8c359f1817a80320e" origin="repo.maven.apache.org/maven2/"/>
<component group="org.apache.commons" name="commons-parent" version="79">
<artifact name="commons-parent-79.pom">
<sha256 value="628df30148acd3c491cfcb6b73c7ae4b5989e5526ab13a2f428dea5d4ad10d7a" origin="repo.maven.apache.org/maven2/"/>
</artifact>
</component>
</components>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.17.2</version>
<version>1.18.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Loading

0 comments on commit 93c93ea

Please sign in to comment.