Skip to content

Add buf_01#20

Open
eemhu wants to merge 45 commits intoteragrep:mainfrom
eemhu:buf_01
Open

Add buf_01#20
eemhu wants to merge 45 commits intoteragrep:mainfrom
eemhu:buf_01

Conversation

@eemhu
Copy link
Copy Markdown

@eemhu eemhu commented Mar 27, 2026

  • Replace internal buffer with buf_01 dependency 1.1.0
  • TrackedMemorySegmentLease moved to buf_01 1.1.0
  • Replace internal pool with poj_01 dependency 3.0.0
  • Ingress tests to ServerTest
  • Egress tests to ServerTest
  • Update JDK to version 25
  • SocketTest (Plain socket)
  • SocketTest (TLS socket)
  • Various Clock fakes
  • Socket returns IOResult, uses TrackedMemorySegmentLeases
  • Update Jacoco Maven Plugin to 0.8.14
  • Ingress uses TrackedMemorySegmentLeases
  • Egress uses TrackedMemorySegmentLeases
  • Test Writeables
  • Test that Leases are properly closed and returned to pool.
  • Array vs. List performance Add buf_01 #20 (comment)

@eemhu eemhu self-assigned this Mar 27, 2026
@eemhu eemhu linked an issue Mar 27, 2026 that may be closed by this pull request
Comment thread src/main/java/com/teragrep/net_01/channel/buffer/TrackedMemorySegmentLease.java Outdated
Comment thread src/main/java/com/teragrep/net_01/channel/buffer/TrackedMemorySegmentLease.java Outdated
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was trying to avoid List conversions from arrays[] as they come with allocation overhead. Have you measured the impact in profiler? Same goes to all new calls.

@eemhu eemhu marked this pull request as ready for review April 24, 2026 12:18
@eemhu eemhu requested a review from kortemik April 28, 2026 07:59
for (ByteBuffer byteBuffer : buffers()) {
byteBuffer.limit(0);
for (final TrackedLease<MemorySegment> lease : memorySegmentLeases()) {
try {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can a lease throw in close?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It can throw IllegalStateException; however AutoCloseable interface defines that it throws Exception on close. I think buf_01 Lease interface needs to define a different exception in interface to work around this.

Comment thread src/main/java/com/teragrep/net_01/channel/context/IngressImpl.java
Comment thread src/main/java/com/teragrep/net_01/channel/context/IngressImpl.java
if (!allWritten && bytesWritten > 0) {
// same as ByteBuffer.flip()
final long diff = bytesLeft - byteSize;
if (diff < 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nested control structures are error prone. please consider simplifying

if (!allRead && readBytes > 0) {
// same as ByteBuffer.flip()
final long diff = bytesLeft - byteSize;
if (diff < 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nested control structures are error prone. please consider simplifying

Comment thread src/main/java/com/teragrep/net_01/eventloop/EventLoop.java Outdated
Comment thread src/main/java/com/teragrep/net_01/server/ServerFactory.java Outdated
Comment thread src/main/java/com/teragrep/net_01/channel/buffer/writable/WriteableLeaseful.java Outdated
Comment thread src/main/java/com/teragrep/net_01/channel/context/EgressImpl.java Outdated

private long readData() throws IOException {
long readBytes = 0;
final List<OpenableLease<MemorySegment>> bufferLeases = new LeaseMultiGet(memorySegmentLeasePool).get(4);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would it be feasible to change multiget to return an array?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if this uses TrackedMemorySegmentLease's always, would it be better to return alwayys them ready as TrackedMemorySegmentLeases via a decorator?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think it would be quite trivial change, however it would be done in buf_01 project

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Refactor net_01 to use buf_01

2 participants