From d2280ad9e239fb686bcc1df74fa465dba50b235c Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 23 Jun 2024 17:08:58 +0200 Subject: perf: Reuse a single JsonProvider. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This speeds up the formatter significantly. Before: Benchmark Mode Cnt Score Error Units FormatterBenchmark.massivelyStructuredLogRecord thrpt 10 6552.727 ± 2169.572 ops/s FormatterBenchmark.simpleLogRecord thrpt 10 8126.699 ± 2259.912 ops/s FormatterBenchmark.structuredLogRecord thrpt 10 5594.849 ± 1129.151 ops/s After: Benchmark Mode Cnt Score Error Units FormatterBenchmark.massivelyStructuredLogRecord thrpt 10 137879.001 ± 30467.644 ops/s FormatterBenchmark.simpleLogRecord thrpt 10 896085.217 ± 249890.421 ops/s FormatterBenchmark.structuredLogRecord thrpt 10 553428.807 ± 194787.754 ops/s Change-Id: If184327a4ff0de0d92b769493dbf6270ba3a8c8e --- .../eu/mulk/quarkus/googlecloud/jsonlogging/FormatterTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'core/src/test/java') diff --git a/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterTest.java b/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterTest.java index b755230..6d40b15 100644 --- a/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterTest.java +++ b/core/src/test/java/eu/mulk/quarkus/googlecloud/jsonlogging/FormatterTest.java @@ -2,7 +2,7 @@ package eu.mulk.quarkus.googlecloud.jsonlogging; import static org.junit.jupiter.api.Assertions.assertLinesMatch; -import jakarta.json.Json; +import jakarta.json.spi.JsonProvider; import java.util.Collection; import java.util.List; import org.jboss.logmanager.ExtLogRecord; @@ -11,6 +11,8 @@ import org.junit.jupiter.api.Test; class FormatterTest { + private static final JsonProvider JSON = JsonProvider.provider(); + @Test void simpleRecord() { var logRecord = makeSimpleRecord(); @@ -43,7 +45,7 @@ class FormatterTest { new StructuredParameterProvider() { @Override public StructuredParameter getParameter() { - var b = Json.createObjectBuilder(); + var b = JSON.createObjectBuilder(); b.add("traceId", "39f9a49a9567a8bd7087b708f8932550"); b.add("spanId", "c7431b14630b633d"); return () -> b; @@ -88,7 +90,7 @@ class FormatterTest { logRecord.setParameters( new Object[] { (StructuredParameter) - () -> Json.createObjectBuilder().add("one", 1).add("two", 2.0).add("yes", true), + () -> JSON.createObjectBuilder().add("one", 1).add("two", 2.0).add("yes", true), Label.of("a", "b") }); return logRecord; @@ -128,7 +130,7 @@ class FormatterTest { new Object[] { (StructuredParameter) () -> { - var b = Json.createObjectBuilder(); + var b = JSON.createObjectBuilder(); for (int i = 0; i < 10; i++) { b.add("int-" + i, i); } -- cgit v1.2.3