This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git
The following commit(s) were added to refs/heads/main by this push:
new da6b5ce2b perf(java): optimize json perf regression (#3866)
da6b5ce2b is described below
commit da6b5ce2bda38b3762e4bf13175ac1887220f940
Author: Shawn Yang <[email protected]>
AuthorDate: Thu Jul 16 21:13:13 2026 +0530
perf(java): optimize json perf regression (#3866)
## Why?
## What does this PR do?
## Related issues
## AI Contribution Checklist
- [ ] Substantial AI assistance was used in this PR: `yes` / `no`
- [ ] If `yes`, I included a completed [AI Contribution
Checklist](https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs)
in this PR description and the required `AI Usage Disclosure`.
- [ ] If `yes`, my PR description includes the required `ai_review`
summary and screenshot evidence or equivalent persisted links of the
final clean AI review results from both fresh reviewers described in
`AI_POLICY.md`, the Fory-guided reviewer and the independent general
reviewer, on the current PR diff or current HEAD after the latest code
changes.
## Does this PR introduce any user-facing change?
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
---
.../src/main/java/org/apache/fory/json/reader/JsonReader.java | 4 ----
.../src/main/java/org/apache/fory/json/reader/Latin1JsonReader.java | 5 +++++
.../src/main/java/org/apache/fory/json/reader/Utf16JsonReader.java | 5 +++++
.../src/main/java/org/apache/fory/json/reader/Utf8JsonReader.java | 5 +++++
4 files changed, 15 insertions(+), 4 deletions(-)
diff --git
a/java/fory-json/src/main/java/org/apache/fory/json/reader/JsonReader.java
b/java/fory-json/src/main/java/org/apache/fory/json/reader/JsonReader.java
index 6cb40fc72..387b226a0 100644
--- a/java/fory-json/src/main/java/org/apache/fory/json/reader/JsonReader.java
+++ b/java/fory-json/src/main/java/org/apache/fory/json/reader/JsonReader.java
@@ -135,7 +135,6 @@ public abstract class JsonReader {
private final JsonTypeResolver typeResolver;
protected int position;
private final int maxDepth;
- protected final FieldNameCache fieldNameCache;
private int depth;
/**
@@ -234,9 +233,6 @@ public abstract class JsonReader {
protected JsonReader(JsonConfig config, JsonTypeResolver typeResolver) {
this.typeResolver = Objects.requireNonNull(typeResolver, "typeResolver");
maxDepth = config.maxDepth();
- // The configured limit belongs to each reader; pooled-state concurrency
must not divide it.
- int maxEntries = config.maxCachedFieldNames();
- fieldNameCache = maxEntries == 0 ? null : new FieldNameCache(maxEntries);
}
/**
diff --git
a/java/fory-json/src/main/java/org/apache/fory/json/reader/Latin1JsonReader.java
b/java/fory-json/src/main/java/org/apache/fory/json/reader/Latin1JsonReader.java
index f2a81c518..cbe2a16ec 100644
---
a/java/fory-json/src/main/java/org/apache/fory/json/reader/Latin1JsonReader.java
+++
b/java/fory-json/src/main/java/org/apache/fory/json/reader/Latin1JsonReader.java
@@ -79,10 +79,15 @@ public final class Latin1JsonReader extends JsonReader {
// Latin1 string content and field-name hashing must keep unsigned byte
conversion.
private byte[] input;
private byte[] stringDecodeBuffer = new
byte[INITIAL_STRING_DECODE_BUFFER_SIZE];
+ // Keep the cache after hot representation fields; an inherited reference
shifts their offsets.
+ private final FieldNameCache fieldNameCache;
public Latin1JsonReader(JsonConfig config, JsonTypeResolver typeResolver) {
super(config, typeResolver);
input = EMPTY_BYTES;
+ // The configured limit belongs to each reader; pooled-state concurrency
must not divide it.
+ int maxEntries = config.maxCachedFieldNames();
+ fieldNameCache = maxEntries == 0 ? null : new FieldNameCache(maxEntries);
}
@Override
diff --git
a/java/fory-json/src/main/java/org/apache/fory/json/reader/Utf16JsonReader.java
b/java/fory-json/src/main/java/org/apache/fory/json/reader/Utf16JsonReader.java
index a5c896127..97bcf8d04 100644
---
a/java/fory-json/src/main/java/org/apache/fory/json/reader/Utf16JsonReader.java
+++
b/java/fory-json/src/main/java/org/apache/fory/json/reader/Utf16JsonReader.java
@@ -76,12 +76,17 @@ public final class Utf16JsonReader extends JsonReader {
private byte[] bytes;
private int length;
private byte[] stringDecodeBuffer = new
byte[INITIAL_STRING_DECODE_BUFFER_SIZE];
+ // Keep the cache after hot representation fields; an inherited reference
shifts their offsets.
+ private final FieldNameCache fieldNameCache;
public Utf16JsonReader(JsonConfig config, JsonTypeResolver typeResolver) {
super(config, typeResolver);
input = "";
bytes = null;
length = 0;
+ // The configured limit belongs to each reader; pooled-state concurrency
must not divide it.
+ int maxEntries = config.maxCachedFieldNames();
+ fieldNameCache = maxEntries == 0 ? null : new FieldNameCache(maxEntries);
}
@Override
diff --git
a/java/fory-json/src/main/java/org/apache/fory/json/reader/Utf8JsonReader.java
b/java/fory-json/src/main/java/org/apache/fory/json/reader/Utf8JsonReader.java
index 6e5240cb7..b6b9492cd 100644
---
a/java/fory-json/src/main/java/org/apache/fory/json/reader/Utf8JsonReader.java
+++
b/java/fory-json/src/main/java/org/apache/fory/json/reader/Utf8JsonReader.java
@@ -81,10 +81,15 @@ public final class Utf8JsonReader extends JsonReader {
// UTF-8 string decoding must keep unsigned byte conversion for non-ASCII
content.
private byte[] input;
private byte[] stringDecodeBuffer = new
byte[INITIAL_STRING_DECODE_BUFFER_SIZE];
+ // Keep the cache after hot representation fields; an inherited reference
shifts their offsets.
+ private final FieldNameCache fieldNameCache;
public Utf8JsonReader(JsonConfig config, JsonTypeResolver typeResolver) {
super(config, typeResolver);
input = EMPTY_BYTES;
+ // The configured limit belongs to each reader; pooled-state concurrency
must not divide it.
+ int maxEntries = config.maxCachedFieldNames();
+ fieldNameCache = maxEntries == 0 ? null : new FieldNameCache(maxEntries);
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]