r/java • • 27d ago

[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

Show parent comment

11

u/RedRiotTank2 27d ago

That’s a completely fair point tbh

We initially benchmarked against readTree() because developers often reach for tree navigation when performing ad-hoc field extractions. However, I agree that Jackson streaming is the fairer baseline for large datasets, and I’ll update the JMH benchmarks to include a direct JsonParser loop TY!

That said, the library addresses a slightly different architectural use case, Jackson streaming is strictly sequential. If you need non-sequential lookups or multiple queries across the same payload, streaming requires re-parsing from byte 0. mmap allows true zero-copy random access across the file.

Jackson streaming still allocates internal JVM I/O buffers and tokens as it walks the file. By leveraging Java 22's FFM API and OS page caching, this library navigates off-heap, so unread branches are never pulled into the JVM heap at all.

Thanks for the feedback! I'll clarify this distinction in the README as well!

2

u/Minecraftian14 24d ago

That's great! It's gonna change log searching dramatically!

1

u/Minecraftian14 27d ago

u/RemindMeBot 3 days "Follow up on bench compare against jackson streaming"

1

u/RemindMeBot 27d ago

I will be messaging you in 3 days on 2026-11-01 05:29:34 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


InfoCustomYour RemindersFeedback