Vector API use for JRuby's json library
Jatin Bhateja
jatinbha.cloud at gmail.com
Tue Aug 5 16:50:12 UTC 2025
Hi All,
As discussed, I made changes in Utf8Validator[1] to use newly optimized
Vector.slice API with constant slice index[2]
and see around 1.35x gain with this small change.
Baseline:
Utf8ValidatorBenchmark.utf8Validator
twitter.json
N/A thrpt 2 60140.708 ops/s
With optimization:
Utf8ValidatorBenchmark.utf8Validator
twitter.json
N/A thrpt 2 79926.621 ops/s
Benchmarking system: AMD Ryzen 7 7840HS 8C 16T AVX512
Please note my results are w.r.t to current JDK-mainline with and without
patch[1] and [2].
Will create pull request against simdjson-java after some more validations
and bumping its minimum build version to JDK-24.
I now plan to look at optimizing lookup tables using new Vector.selectFrom
API[3]
Best Regards,
Jatin
[1]
https://github.com/simdjson/simdjson-java/compare/main...jatin-bhateja:simdjson-java:jdk_24_changes#diff-3c7915a592a6357171dec9388a1c87ee46d96cd7e95ff7efb3fe58da3f1f5b6e
[2] https://github.com/openjdk/jdk/pull/24104
[3]
https://docs.oracle.com/en/java/javase/24/docs/api/jdk.incubator.vector/jdk/incubator/vector/Vector.html#selectFrom(jdk.incubator.vector.Vector,jdk.incubator.vector.Vector)
On Mon, Aug 4, 2025 at 9:50 PM Jatin Bhateja <jatinbha.cloud at gmail.com>
wrote:
> Following JMH micro-benchmark shows 50x improvement in JSON structural
> character lookup using new Vector.selectFrom API which can operate on 128
> byte lookup table.
>
> https://github.com/ionutbalosin/jvm-performance-benchmarks/pull/105
>
> I plan to explore and modify existing UTF8Validator and StructuralIndexer
> components of https://github.com/simdjson/simdjson-java library.
>
> Best Regards,
>
> Jatin
>
> On 7/31/2025 8:33 PM, Charles Oliver Nutter wrote:
>
> The developer experimenting with vectors has been running 21, so I did
> suggest to him recently to try newer releases or dev builds. I'm out of
> office right now but hoping to spend some time in the next week running
> this through a profiler to see if other missed optimizations are
> interfering with the vectorized version of the code.
>
> I also pointed out the other vector-based json project to him that was
> suggested by Daniel. I'm hopeful we can get more out of this than we have
> seen so far once I can help profile and dig into optimized results a little
> bit more.
>
> There are many other places in JRuby where we could use this, such as for
> handling text transcoding. There may even be some Ruby language constructs
> that could be vectorized by JRuby's compiler. I wish I had more hours in
> the day to experiment with this!
>
> On Mon, Jul 28, 2025, 22:40 Paul Sandoz <paul.sandoz at oracle.com> wrote:
>
>> Hi Daniel,
>>
>> Thanks for sharing. We have made progress optimizing the
>> rearrange/selectFrom operations for UTF-8 related uses cases. The
>> improvements were integrated into JDK release 24 [0].
>> Further optimizations are in flight for slice operations with constant
>> inputs [1], which I believe can simplify the referenced code and may
>> further boost performance, but we need to verify.
>>
>> Charlie, what version of the JDK are you using?
>>
>> Paul.
>>
>> [0] https://openjdk.org/jeps/489
>> [1] https://github.com/openjdk/jdk/pull/24104
>>
>> On Jul 16, 2025, at 10:46 AM, Daniel Lemire <daniel at lemire.me> wrote:
>>
>> Good day Charles,
>>
>> The following link might be relevant :
>>
>> https://github.com/simdjson/simdjson-java
>>
>> - Daniel
>>
>> After seeing similar work done for the C version of the Ruby json
>> standard library, I suggested to the author that we could do the same for
>> JRuby using the Vector API. So he went and did it!
>>
>> https://github.com/ruby/json/pull/824
>>
>> The results are somewhat mixed; performance of some cases is faster and
>> other cases is slower. We would love to get input from anyone on this list
>> interested in seeing another real-world use case for the Vector API.
>>
>> I'm hopeful we can pump up these numbers with some additional tweaking in
>> JRuby and json.
>>
>> *Charles Oliver Nutter*
>> *Architect and Technologist*
>> Headius Enterprises
>> https://www.headius.com
>> headius at headius.com
>>
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20250805/2a77022a/attachment-0001.htm>
More information about the panama-dev
mailing list