question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`ObjectMapper` default heap consumption increased significantly from 2.13.x to 2.14.0

See original GitHub issue

Hello,

I’m currently looking at heap consumption when using native image with a Spring Boot 3 application. Spring Boot 3.0 SNAPSHOT uses Jackson 2.14.0-rc3. I noticed that with the upgrade from 2.13.4.2 to 2.14.0 the application uses more heap memory, which i tracked down to this PR. It changed the cache implementation from ConcurrentHashMap to PrivateMaxEntriesMap, which in turn preallocates a lot of AtomicReference (they appear to be all empty).

I created a reproducer here - it creates an empty objectmapper and then dumps the heap. It has more information and screenshots in the README.

When using Jackson 2.13.4.2 it uses 567 B for the LRUmap, with Jackson 2.14.0 it uses 507320 B for the LRU map. The bad thing is that most of these caches are per ObjectMapper - create more of them and it uses even more heap.

As we’re trying to optimize the memory consumption of native image applications, this is quite a bummer and we hope you can help us out here.

Thanks!

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:3
  • Comments:46 (24 by maintainers)

github_iconTop GitHub Comments

6reactions
cowtowncodercommented, Nov 22, 2022

Ta-dah! I did it. 2.14.1 release mostly done, last couple of artifacts on their way to Maven Central (Scala module may take bit longer). Please LMK if you find issues.

3reactions
ben-manescommented, Nov 16, 2022

@pjfanning you forgot to account for the AtomicReference instances themselves. That ranges from 16-32 bytes depending on the jvm optimizations (compressed references, compressed class pointers, byte alignment). In that case you might expect to see it as 16 * 128 (4 + 32) = 73,728 or ~300kb if each mapper uses 4 caches. Using Java Object Layout,

# Running 64-bit HotSpot VM.
# Using compressed oop with 3-bit shift.
# Using compressed klass with 3-bit shift.
# WARNING | Compressed references base/shifts are guessed by the experiment!
# WARNING | Therefore, computed addresses are just guesses, and ARE NOT RELIABLE.
# WARNING | Make sure to attach Serviceability Agent to get the reliable addresses.
# Objects are 8 bytes aligned.
# Field sizes by type: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]
# Array element sizes: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]

... (many variations) ...

***** Hotspot Layout Simulation (JDK 15, 64-bit model, compressed class pointers, 16-byte aligned)
java.util.concurrent.atomic.AtomicReference object internals:
OFF  SZ               TYPE DESCRIPTION               VALUE
  0   8                    (object header: mark)     N/A
  8   4                    (object header: class)    N/A
 12   4                    (alignment/padding gap)
 16   8   java.lang.Object AtomicReference.value     N/A
 24   8                    (object alignment gap)
Instance size: 32 bytes
Space losses: 4 bytes internal + 8 bytes external = 12 bytes total
Read more comments on GitHub >

github_iconTop Results From Across the Web

ObjectMapper (jackson-databind 2.14.1 API) - javadoc.io
Simplest usage is of form: final ObjectMapper mapper = new ObjectMapper(); // can use static singleton, inject: just make sure to reuse! MyValue...
Read more >
Java using much more memory than heap size (or size ...
The OS allocates memory pages lazily, i.e. on the first use, so the actual memory usage will be much lower (typically 80-200 KB...
Read more >
FasterXML Jackson-Databind Issues - IssueHint
`ObjectMapper` default heap consumption increased significantly from 2.13.x to 2.14.0, closed, 46, 2022-11-15, 2022-12-11.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found