From 414e760868c75f56d4175faee204c3ffa4212742 Mon Sep 17 00:00:00 2001 From: wycst Date: Fri, 19 Apr 2024 01:30:24 +0800 Subject: [PATCH] Add the WAST library (#102) --- README.md | 1 + build.gradle | 2 ++ src/main/java/com/github/fabienrenaud/jjb/JsonBench.java | 4 ++++ .../github/fabienrenaud/jjb/databind/Deserialization.java | 5 +++++ .../github/fabienrenaud/jjb/databind/Serialization.java | 7 +++++++ .../java/com/github/fabienrenaud/jjb/model/Clients.java | 4 ++++ src/main/java/com/github/fabienrenaud/jjb/model/Users.java | 4 ++++ .../com/github/fabienrenaud/jjb/support/BenchSupport.java | 4 +++- .../java/com/github/fabienrenaud/jjb/support/Library.java | 3 ++- .../java/com/github/fabienrenaud/jjb/JsonBenchmark.java | 7 +++++++ 10 files changed, 39 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c18a72f..9a7c9af 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ The results here-below were computed on January the 30th, 2024 with the followin | tapestry | 5.8.3 | | underscore | 1.97 | | yasson | 3.0.3 | +| wast | 0.0.12.1 | [All graphs and sheets are available in this google doc.][spreadsheet] diff --git a/build.gradle b/build.gradle index f5fbaee..246c5db 100644 --- a/build.gradle +++ b/build.gradle @@ -98,6 +98,8 @@ dependencies { implementation group: 'org.eclipse', name: 'yasson', version: '3.0.3' // QuickBuffers implementation group: 'us.hebi.quickbuf', name: 'quickbuf-runtime', version: '1.4' + // wast + implementation group: 'io.github.wycst', name: 'wast', version: '0.0.12.1' // Test testImplementation group: 'junit', name: 'junit', version: '4.13.2' diff --git a/src/main/java/com/github/fabienrenaud/jjb/JsonBench.java b/src/main/java/com/github/fabienrenaud/jjb/JsonBench.java index 26a65c0..f17e137 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/JsonBench.java +++ b/src/main/java/com/github/fabienrenaud/jjb/JsonBench.java @@ -135,4 +135,8 @@ public Object quickbuf_json() throws Exception { return null; } + public Object wast() throws Exception { + return null; + } + } diff --git a/src/main/java/com/github/fabienrenaud/jjb/databind/Deserialization.java b/src/main/java/com/github/fabienrenaud/jjb/databind/Deserialization.java index 78f0abc..2d6612d 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/databind/Deserialization.java +++ b/src/main/java/com/github/fabienrenaud/jjb/databind/Deserialization.java @@ -144,4 +144,9 @@ public Object quickbuf_json() throws Exception { .mergeFrom(us.hebi.quickbuf.JsonSource.newInstance(JSON_SOURCE().nextByteArray())); } + @Benchmark + @Override + public Object wast() throws Exception { + return io.github.wycst.wast.json.JSON.parseObject(JSON_SOURCE().nextString(), JSON_SOURCE().pojoType()); + } } diff --git a/src/main/java/com/github/fabienrenaud/jjb/databind/Serialization.java b/src/main/java/com/github/fabienrenaud/jjb/databind/Serialization.java index f750014..9f82267 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/databind/Serialization.java +++ b/src/main/java/com/github/fabienrenaud/jjb/databind/Serialization.java @@ -175,4 +175,11 @@ public Object quickbuf_json() throws Exception { return JSON_SOURCE().provider().quickbufSink().clear().writeMessage(JSON_SOURCE().nextQuickbufPojo()); } + @Benchmark + @Override + public Object wast() throws Exception { + ByteArrayOutputStream baos = JsonUtils.byteArrayOutputStream(); + io.github.wycst.wast.json.JSON.writeJsonTo(JSON_SOURCE().nextPojo(), baos); + return baos; + } } diff --git a/src/main/java/com/github/fabienrenaud/jjb/model/Clients.java b/src/main/java/com/github/fabienrenaud/jjb/model/Clients.java index aef1cfe..26d9a32 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/model/Clients.java +++ b/src/main/java/com/github/fabienrenaud/jjb/model/Clients.java @@ -5,6 +5,7 @@ import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter; import com.dslplatform.json.CompiledJson; import com.dslplatform.json.JsonAttribute; +import io.github.wycst.wast.json.annotations.JsonTypeSetting; import java.math.BigDecimal; import java.time.LocalDate; @@ -18,6 +19,7 @@ @JsonObject @CompiledJson @jodd.json.meta.JSON +@JsonTypeSetting(enableJIT = true) public class Clients { @JsonField @@ -58,6 +60,7 @@ public void setClients(List clients) { @io.avaje.jsonb.Json @JsonObject + @JsonTypeSetting(enableJIT = true) public static final class Client { @JsonField @@ -395,6 +398,7 @@ public static EyeColor fromNumber(int i) { @io.avaje.jsonb.Json @JsonObject + @JsonTypeSetting(enableJIT = true) public static final class Partner { @JsonField diff --git a/src/main/java/com/github/fabienrenaud/jjb/model/Users.java b/src/main/java/com/github/fabienrenaud/jjb/model/Users.java index dd221a2..39acdc1 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/model/Users.java +++ b/src/main/java/com/github/fabienrenaud/jjb/model/Users.java @@ -4,6 +4,7 @@ import com.bluelinelabs.logansquare.annotation.JsonObject; import com.dslplatform.json.CompiledJson; import com.dslplatform.json.JsonAttribute; +import io.github.wycst.wast.json.annotations.JsonTypeSetting; import java.util.List; import java.util.Objects; @@ -12,6 +13,7 @@ @JsonObject @CompiledJson @jodd.json.meta.JSON +@JsonTypeSetting(enableJIT = true) public class Users { @JsonField @@ -53,6 +55,7 @@ public void setUsers(List users) { @io.avaje.jsonb.Json @JsonObject @CompiledJson + @JsonTypeSetting(enableJIT = true) public static final class User { @JsonField @@ -329,6 +332,7 @@ public void setFavoriteFruit(String favoriteFruit) { @io.avaje.jsonb.Json @JsonObject @CompiledJson + @JsonTypeSetting(enableJIT = true) public static final class Friend { @JsonField diff --git a/src/main/java/com/github/fabienrenaud/jjb/support/BenchSupport.java b/src/main/java/com/github/fabienrenaud/jjb/support/BenchSupport.java index 90ae27d..d85d75b 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/support/BenchSupport.java +++ b/src/main/java/com/github/fabienrenaud/jjb/support/BenchSupport.java @@ -37,7 +37,8 @@ public enum BenchSupport { new Libapi(Library.QSON, Api.DATABIND), new Libapi(Library.PUREJSON, Api.STREAM), new Libapi(Library.ANTONS, Api.STREAM), - new Libapi(Library.QUICKBUF_JSON, Api.DATABIND) + new Libapi(Library.QUICKBUF_JSON, Api.DATABIND), + new Libapi(Library.WAST, Api.DATABIND) ), CLIENTS( new Libapi(Library.GSON, Api.DATABIND), @@ -63,6 +64,7 @@ public enum BenchSupport { new Libapi(Library.NANOJSON), new Libapi(Library.JODD, Api.DATABIND), new Libapi(Library.MOSHI, Api.DATABIND), + new Libapi(Library.WAST, Api.DATABIND), new Libapi(Library.TAPESTRY), new Libapi(Library.MINIMALJSON), new Libapi(Library.UNDERSCORE_JAVA), diff --git a/src/main/java/com/github/fabienrenaud/jjb/support/Library.java b/src/main/java/com/github/fabienrenaud/jjb/support/Library.java index 29405f4..7f61f57 100644 --- a/src/main/java/com/github/fabienrenaud/jjb/support/Library.java +++ b/src/main/java/com/github/fabienrenaud/jjb/support/Library.java @@ -35,7 +35,8 @@ public enum Library { UNDERSCORE_JAVA, PUREJSON, ANTONS, - QUICKBUF_JSON; + QUICKBUF_JSON, + WAST; public static Set fromCsv(String str) { if (str == null || str.trim().isEmpty()) { diff --git a/src/test/java/com/github/fabienrenaud/jjb/JsonBenchmark.java b/src/test/java/com/github/fabienrenaud/jjb/JsonBenchmark.java index 2aecd82..05c9679 100644 --- a/src/test/java/com/github/fabienrenaud/jjb/JsonBenchmark.java +++ b/src/test/java/com/github/fabienrenaud/jjb/JsonBenchmark.java @@ -279,4 +279,11 @@ public void quickbuf_json() throws Exception { } } + @Test + public void wast_json() throws Exception { + for (int i = 0; i < ITERATIONS; i++) { + test(Library.WAST, BENCH.wast()); + } + } + }