Skip to content

[Experimental] Add MemorySegment API support for zero-copy buffer I/O#2904

Draft
divang wants to merge 4 commits intomainfrom
user/divang/memorysegment-buffer-optimization
Draft

[Experimental] Add MemorySegment API support for zero-copy buffer I/O#2904
divang wants to merge 4 commits intomainfrom
user/divang/memorysegment-buffer-optimization

Conversation

@divang
Copy link
Copy Markdown
Contributor

@divang divang commented Mar 3, 2026

  • Implement BufferAllocator interface with strategy pattern
  • Add HeapBufferAllocator for traditional ByteBuffer (Java 8+)
  • Add MemorySegmentBufferAllocator for zero-copy I/O (Java 22+)
  • Update IOBuffer to use reflection-based factory for allocator selection
  • Configure pom.xml for dual compilation (Java 8 + Java 22 targets)
  • Add comprehensive performance comparison test suite
  • System property: mssql.jdbc.useMemorySegment=true/false

- Implement BufferAllocator interface with strategy pattern
- Add HeapBufferAllocator for traditional ByteBuffer (Java 8+)
- Add MemorySegmentBufferAllocator for zero-copy I/O (Java 22+)
- Update IOBuffer to use reflection-based factory for allocator selection
- Configure pom.xml for dual compilation (Java 8 + Java 22 targets)
- Add comprehensive performance comparison test suite
- System property: mssql.jdbc.useMemorySegment=true/false
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 38.18182% with 102 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.39%. Comparing base (53b6a4a) to head (39b9b48).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...in/java/com/microsoft/sqlserver/jdbc/IOBuffer.java 42.00% 71 Missing and 16 partials ⚠️
...t/sqlserver/jdbc/MemorySegmentBufferAllocator.java 0.00% 11 Missing ⚠️
.../microsoft/sqlserver/jdbc/HeapBufferAllocator.java 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2904      +/-   ##
============================================
- Coverage     60.64%   60.39%   -0.26%     
+ Complexity     4913     4902      -11     
============================================
  Files           151      152       +1     
  Lines         34986    35134     +148     
  Branches       5849     5879      +30     
============================================
  Hits          21218    21218              
- Misses        10927    11051     +124     
- Partials       2841     2865      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

divang added 2 commits March 3, 2026 18:58
- Introduce BufferMode enum: HEAP, DIRECT_BUFFER, MEMORY_SEGMENT
- Convert TDSPacket.payload from byte[] to ByteBuffer for zero-copy reads
- Implement ByteBuffer.read() in TDSChannel for efficient I/O
- Update TDSReader methods to use native ByteBuffer operations
- Add automatic SSL-aware fallback (MEMORY_SEGMENT -> DIRECT_BUFFER)
- Support legacy mssql.jdbc.useMemorySegment property
@machavan machavan changed the title Add MemorySegment API support for zero-copy buffer I/O [Experimental] Add MemorySegment API support for zero-copy buffer I/O Mar 18, 2026
@divang divang self-assigned this Apr 2, 2026
- Implement HEAP, DIRECT_BUFFER, and MEMORY_SEGMENT buffer modes

- Add SSLEngine support for zero-copy I/O with TLS

- Validated performance gains: READ 26-43% faster, WRITE 13-36% faster for binary

- Smart fallback: MEMORY_SEGMENT -> DIRECT_BUFFER when SSL active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

1 participant