FasterXML / FasterXML/jackson-core

Allow automatic canonicalization (possibly `String.intern()`) of `JsonToken.VALUE_STRING` values

Đang mở
#726 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
pr-needed
Ngôn ngữ chính
Java
Star
2.4k
Fork
928
Merge trung bình
2 ngày 18 giờ
Pull request đã merge (30 ngày)
24

Mô tả

## 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;
}
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.