Skip to content

Conversation

@dain
Copy link
Member

@dain dain commented Jan 31, 2026

This PR:

  • Replace unsafe with MemorySegment for the Slice copy to/from primitive[].
  • Remove unused JvmUtils
  • Replace JOL with simple size computation based on probing the JVM configs

Performance Testing (MemorySegment conversion):

Benchmarked Slice.getLongs()/setLongs() comparing Unsafe.copyMemory vs MemorySegment.copy on JDK 25:

Array Size Unsafe (ns/op) MemorySegment (ns/op) Result
32 elements ~38 ~28 24-29% faster
1024 elements ~130 ~130 equivalent
32768 elements ~3400 ~3400 equivalent
  • MemorySegment performs better than Unsafe for small primitive[] copy operations.
  • System.arraycopy (used for byte[] copies in setBytes) is unchanged as it outperforms both for that use case.

@dain dain requested review from electrum and wendigo January 31, 2026 09:10

// Determine reference size based on UseCompressedOops
// Default is true for heaps < 32GB on 64-bit JVMs
boolean compressedOops = getBooleanVmOption(hotSpotBean, "UseCompressedOops", true);
Copy link
Member

Choose a reason for hiding this comment

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

Is the flag textual value an integer?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I wrote tests. booleans give you true/false, and number ones give you numbers.

@dain dain changed the title Remove unsafe and update to Java 25 Remove unsafe Feb 1, 2026
@wendigo
Copy link
Contributor

wendigo commented Feb 1, 2026

@dain before merging this can you release a snapshot so that we can benchmark this in Trino?

JOL already did not work on records, and uses unsafe.
Use HotSpotDiagnosticMXBean to query JVM options that determine object
header sizes, use reflection to get field types, and handle alignment.
@dain
Copy link
Member Author

dain commented Feb 2, 2026

Sure, I published slice-2.5-20260202.012431-1. Please run the benchmarks soon, and if you seem a problem be specific.

wendigo added a commit to trinodb/trino that referenced this pull request Feb 2, 2026
@wendigo
Copy link
Contributor

wendigo commented Feb 2, 2026

@dain testing here: trinodb/trino#28075

@dain dain merged commit 181b598 into airlift:master Feb 2, 2026
1 check passed
@dain dain deleted the remove-unsafe branch February 2, 2026 20:45
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