FasterXML / FasterXML/jackson-core
Allow automatic canonicalization (possibly `String.intern()`) of `JsonToken.VALUE_STRING` values
- 主要语言
- Java
- 星标
- 2.4k
- 派生
- 928
- 平均合并
- 2 天 18 小时
- 30 天内合并 PR
- 24
描述
## Version
2.12.4
## Feature request
#### Existing scenario
I think the `INTERN_FIELD_NAMES` flag is great thing to have, which is turned on by default. This would save greatly on the memory footprint especially when the message size is huge, imagine ~3.2 million position messages, all with same key like 'portfolio', 'book'.
Instead of having ~3.2 million of `portfolio` in parsing each batch of message in heap, with `INTERN_FIELD_NAMES`, it would result in only one `portfolio` on the string pool regardless of the message sizes, being ~3.2 million or even more.
#### Changes proposed
A similar feature flag could be provided, even turned on by default as well, when parsing the values.
So that, back to the ~3.2 million records example, instead of having ~3.2 million portfolio names in the heap, the similar feature flag would result in only around ~200 `portfolio name` (like Jason, Jackson) in the string pool.
## Possible changes
From here, it could take in the feature flag, and apply the intern if the flag is on
https://github.com/FasterXML/jackson-core/blob/2.14/src/main/java/com/fasterxml/jackson/core/util/TextBuffer.java#L797
```
public String setCurrentAndReturn(int len) {
_currentSize = len;
// We can simplify handling here compared to full `contentsAsString()`:
if (_segmentSize > 0) { // longer text; call main method
return contentsAsString();
}
// more common case: single segment
int currLen = _currentSize;
String str = (currLen == 0) ? "" : new String(_currentSegment, 0, currLen);
if (JsonFactory.Feature.`INTERN_FIELD_VALUES`.enabledIn(_flags)) {
str = InternCache.instance.intern(str );
}
_resultString = str;
return str;
}
```
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。