Nuno Santos created OAK-12448:
---------------------------------

             Summary: Use byte-array UTF-8 decoding for inline segment strings
                 Key: OAK-12448
                 URL: https://issues.apache.org/jira/browse/OAK-12448
             Project: Jackrabbit Oak
          Issue Type: Improvement
          Components: segment-tar
            Reporter: Nuno Santos


h2. Motivation

SegmentData.readString currently decodes inline strings using 
Buffer.decode(StandardCharsets.UTF\_8).toString(). This creates an intermediate 
character buffer and copies the decoded characters into the resulting string.

Constructing a string directly from UTF-8 bytes allows the JDK to use its 
optimized decoding paths, including ASCII fast paths and compact strings.

h2. Proposed changes
* Extract inline string decoding into SegmentData.decodeString(int 
recordReferenceOffset, int length).
* Allocate a byte array and copy the encoded bytes using the existing 
readBytes(...).get(byte[]) APIs.
* Decode with new String(bytes, StandardCharsets.UTF\_8).
* Leave the externally stored large-string path unchanged.
* Introduce no new oak-commons API dependency.

h2. Validation

Add string round-trip tests for empty strings, ASCII, multibyte UTF-8 and 
supplementary characters. Cover lengths around the small/medium/large storage 
boundaries (including 127/128/129 and 16511/16512/16513 bytes), plus externally 
stored large strings. Verify malformed UTF-8 replacement behavior.

h2. Preliminary performance evidence

The original implementation reports a JMH 1.37 A/B comparison of the decoding 
strategies on JDK 23, using average time and the GC profiler:

||Input||Before ns/op||After ns/op||Before B/op||After B/op||
|ASCII, 8|19.3|4.9|192|48|
|ASCII, 40|23.1|6.9|288|80|
|ASCII, 200|35.3|11.4|768|240|
|ASCII, 4000|471|146|12168|4040|
|Multibyte, 200|158|125|824|832|
|Multibyte, 4000|2995|2400|12984|15272|

These are reported decoding-strategy microbenchmarks, not independently 
reproduced results or end-to-end Oak measurements. They show substantial 
improvements for ASCII, but not a universal allocation reduction: the large 
multibyte case allocates more. Include a reproducible benchmark harness and 
verify results on the contribution baseline before drawing precise performance 
conclusions.

h2. Relationship to OAK-12446

This is an independently adoptable first step, using only existing Buffer APIs. 
OAK-12446 can subsequently remove intermediate Buffer/ByteBuffer views through 
a new absolute bulk-read API. The two optimizations should be contributed 
separately so the decoding change does not depend on the new oak-commons API.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to