r/java • • Oct 28 '26

[Open Source] Off-heap, zero-allocation JSON navigator for Java 22+ (using FFM / mmap)

Hi guys,

About a year ago I ran into a bottleneck at work: processing large JSON exports and log dumps inside memory-constrained containers when we only needed to extract a couple of specific fields. Standard parsers like Jackson's readTree were blowing up JVM heap allocations and triggering noticeable GC pause times.

So I made a rough prototype using the Foreign Function & Memory API (JEP 454) to mmap files off-heap and navigate target keys lazily. Over the past few days I finally had time to clean it up, publish it to Maven Central, and benchmark it with JMH against Jackson Databind.

On large datasets (100MB+), it achieves ~2.9x faster in-memory lookups, ~5x faster disk-to-query ingestion, and reduces heap allocation down to a few kilobytes per query.

To be clear, this is NOT a general-purpose Jackson replacement:

  • It does not mutate or write JSON.
  • It does not do POJO / DTO data binding.
  • It is designed for internal/trusted workloads (dumps, logs, pipeline files) rather than complex external schema validation.
  • Maximum file size is currently 2 GB.

It requires Java 22+ and has zero external runtime dependencies.

I'm sharing it in case it's helpful for similar off-heap or container-constrained workloads. I'd love to hear your feedback, critique, or ideas on potential optimizations:

https://github.com/RedRiotTank/NativeJsonNavigator

Edit: Added Jackson Streaming Benchmarks

Thanks to u/_predator_ for pointing out that Jackson Streaming is a fairer baseline for large files than readTree(), I've updated the JMH benchmarks and README with a direct JsonParser token loop:

  • Cold Single-Pass from Disk: Jackson Streaming and this library are effectively at parity on large files (~300 ms and ~3 KB heap per query on 100 MB).
  • In-Memory Traversal: Off-heap navigation remains ~20% faster while allocating ~40–65% less heap than Jackson Streaming.
  • Core Trade-off: Jackson Streaming is strictly forward/sequential. If you need to execute multiple queries or random lookups across the same payload, you have to re-read and re-tokenize from byte 0 each time.

This library maps the file once off-heap via FFM (JEP 454), enabling random-access point queries without holding an object tree in the JVM heap.

Full benchmark tables and raw JMH JSON reports are updated on GitHub!

37 Upvotes

30 comments sorted by

View all comments

4

u/agentoutlier Oct 28 '26

I only spent like 5 seconds looking at this but I think you could use SIMD for the parsing right since you are already using jep 454 might as well use vector api right? Maybe you already do this and I missed it?

2

u/stefanos-ak Oct 28 '26 edited Oct 28 '26

doesn't SIMD require uniform data and operations (like add/mul), in order for it to make any sense? e.g. https://www.elastic.co/search-labs/blog/bbq-vector-comparison-simd-instructions

edit: by "sense" I mean, to actually accelerate the hardware in a way that would be slower without SIMD (assuming you are doing THE EXACT same thing). But I have never played with it so it's an honest question. Not trying to be smart...

2

u/agentoutlier Oct 29 '26 edited Oct 29 '26

Roughly speaking and while I know what SIMD is I am not very good at using so take this explanation kind of crappy laymen.

SIMD allows you todo multiple operations at the same time. While parsing does not seem like math it is as characters can be represented as numbers.

So typically for parsing instead of going character by character you go N number of characters (lets ignore code points and EOF etc for a second and fast discarding of whitespace). N being the number channels? (I think its called that... EDIT lanes. Its called lanes.) your processor supports for SIMD. You can I think also do this by lines instead of characters but it depends on the format I assume.

So sort of instead of some conjunction (and aka &&) which would require several comparisons for look ahead you can make that one operation.

1

u/RedRiotTank2 Oct 29 '26

Not just math, but it is also insanely effective for text parsing. Check this: https://arxiv.org/pdf/1902.08318

it definitely makes sense for JSON, it's just a matter of waiting for the Java Vector API to exit the incubator stage.

2

u/RedRiotTank2 Oct 29 '26

You didn't miss it. SIMD hasn't been added (yet).

The main reason is that while JEP 454 is final in Java 22, the Vector API is still an incubating module, which was banned on my company.

I'm definitely using SIMD once the Vector API stabilizes, but I'm not sure if is it worth using it on previous Java versions. Maybe doing a dual-path setup via a Multi-Release JAR or dynamic fallback if the incubator module is present might be really interesting idea. I'll study it.

1

u/CutGroundbreaking305 29d ago

Bro vector api is technically part of java just use it only thing stopping it is Valhalla and we are going to have it next JDK so mostly we will have vector api by JDK 29

Even apache lucene uses vector api

1

u/RedRiotTank2 28d ago

Corporate compliance bans incubators libraries in many cases.

Also precisely Lucene is a bad example for this. They had to built dynamic fallbacks and multi-release JARs precisely to work around these issues https://github.com/apache/lucene/issues/12302

Will be adding SIMD as an optional dynamic fallback later like Lucene did, but the base library must work without forcing JVM launch flags to be actually usable for everyone (including me and the company I work at).

2

u/CutGroundbreaking305 28d ago

Company and it's policies. I know lucene has multi jar release and it has dynamic fall backs as I constantly work in lucene. Without fallbacks to simd it's very tough to say your library runs on every architecture.

Well vector api will take some time however you can use value classes to reduce heap size.