Skip to content

Avoid off-heap memory growth from JDK direct buffer caching#186

Merged
Ian Streeter (istreeter) merged 1 commit intodevelopfrom
fix-off-heap-memory-growth
Feb 18, 2026
Merged

Avoid off-heap memory growth from JDK direct buffer caching#186
Ian Streeter (istreeter) merged 1 commit intodevelopfrom
fix-off-heap-memory-growth

Conversation

@istreeter
Copy link
Contributor

@istreeter Ian Streeter (istreeter) commented Feb 17, 2026

Jira ref: PDP-2490

Read database files via Files.readAllBytes and pass as an InputStream to DatabaseReader.Builder, instead of passing a File which internally uses FileChannel.read into a heap ByteBuffer. The FileChannel path causes the JDK to allocate and cache temporary direct ByteBuffers in thread-local storage (sun.nio.ch.Util.BufferCache), leading to off-heap memory growth in scenarios where the database is initialized repeatedly.

@coveralls
Copy link

Coveralls (coveralls) commented Feb 18, 2026

Pull Request Test Coverage Report for Build 22133410831

Details

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.3%) to 85.401%

Totals Coverage Status
Change from base Build 21751699059: 0.3%
Covered Lines: 117
Relevant Lines: 137

💛 - Coveralls

@istreeter Ian Streeter (istreeter) force-pushed the fix-off-heap-memory-growth branch 2 times, most recently from 2342cb7 to f7761fe Compare February 18, 2026 02:02
Open database files via FileInputStream and pass to the InputStream-based
DatabaseReader.Builder constructor, instead of passing a File which
internally uses FileChannel.read into a heap ByteBuffer. The FileChannel
path causes the JDK to allocate and cache temporary direct ByteBuffers
in thread-local storage (sun.nio.ch.Util.BufferCache), leading to
off-heap memory growth in scenarios where the database is initialized
repeatedly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@istreeter Ian Streeter (istreeter) merged commit b9f8eca into develop Feb 18, 2026
1 check passed
@istreeter Ian Streeter (istreeter) deleted the fix-off-heap-memory-growth branch February 18, 2026 11:29
private-to-public-sync bot pushed a commit to snowplow/enrich that referenced this pull request Feb 25, 2026
Includes snowplow/scala-maxmind-iplookups#186 which reduces how much
off-heap memory gets used when initializing the IP Lookup enrichment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants