New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#5770] Use heapbuffers by default when using LocalChannel and LocalS… #5792
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
transport/src/main/java/io/netty/channel/local/PreferHeapByteBufAllocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright 2016 The Netty Project | ||
* | ||
* The Netty Project licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.netty.channel.local; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.ByteBufAllocator; | ||
import io.netty.buffer.CompositeByteBuf; | ||
|
||
/** | ||
* Wraps another {@link ByteBufAllocator} and use heapbuffers everywhere except when a direct buffer is explicit | ||
* requested. | ||
*/ | ||
final class PreferHeapByteBufAllocator implements ByteBufAllocator { | ||
private final ByteBufAllocator allocator; | ||
|
||
PreferHeapByteBufAllocator(ByteBufAllocator allocator) { | ||
this.allocator = allocator; | ||
} | ||
|
||
@Override | ||
public ByteBuf buffer() { | ||
return allocator.heapBuffer(); | ||
} | ||
|
||
@Override | ||
public ByteBuf buffer(int initialCapacity) { | ||
return allocator.heapBuffer(initialCapacity); | ||
} | ||
|
||
@Override | ||
public ByteBuf buffer(int initialCapacity, int maxCapacity) { | ||
return allocator.heapBuffer(initialCapacity, maxCapacity); | ||
} | ||
|
||
@Override | ||
public ByteBuf ioBuffer() { | ||
return allocator.heapBuffer(); | ||
} | ||
|
||
@Override | ||
public ByteBuf ioBuffer(int initialCapacity) { | ||
return allocator.heapBuffer(initialCapacity); | ||
} | ||
|
||
@Override | ||
public ByteBuf ioBuffer(int initialCapacity, int maxCapacity) { | ||
return allocator.heapBuffer(initialCapacity, maxCapacity); | ||
} | ||
|
||
@Override | ||
public ByteBuf heapBuffer() { | ||
return allocator.heapBuffer(); | ||
} | ||
|
||
@Override | ||
public ByteBuf heapBuffer(int initialCapacity) { | ||
return allocator.heapBuffer(initialCapacity); | ||
} | ||
|
||
@Override | ||
public ByteBuf heapBuffer(int initialCapacity, int maxCapacity) { | ||
return allocator.heapBuffer(initialCapacity, maxCapacity); | ||
} | ||
|
||
@Override | ||
public ByteBuf directBuffer() { | ||
return allocator.directBuffer(); | ||
} | ||
|
||
@Override | ||
public ByteBuf directBuffer(int initialCapacity) { | ||
return allocator.directBuffer(initialCapacity); | ||
} | ||
|
||
@Override | ||
public ByteBuf directBuffer(int initialCapacity, int maxCapacity) { | ||
return allocator.directBuffer(initialCapacity, maxCapacity); | ||
} | ||
|
||
@Override | ||
public CompositeByteBuf compositeBuffer() { | ||
return allocator.compositeHeapBuffer(); | ||
} | ||
|
||
@Override | ||
public CompositeByteBuf compositeBuffer(int maxNumComponents) { | ||
return allocator.compositeHeapBuffer(maxNumComponents); | ||
} | ||
|
||
@Override | ||
public CompositeByteBuf compositeHeapBuffer() { | ||
return allocator.compositeHeapBuffer(); | ||
} | ||
|
||
@Override | ||
public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) { | ||
return allocator.compositeHeapBuffer(maxNumComponents); | ||
} | ||
|
||
@Override | ||
public CompositeByteBuf compositeDirectBuffer() { | ||
return allocator.compositeDirectBuffer(); | ||
} | ||
|
||
@Override | ||
public CompositeByteBuf compositeDirectBuffer(int maxNumComponents) { | ||
return allocator.compositeDirectBuffer(maxNumComponents); | ||
} | ||
|
||
@Override | ||
public boolean isDirectBufferPooled() { | ||
return allocator.isDirectBufferPooled(); | ||
} | ||
|
||
@Override | ||
public int calculateNewCapacity(int minNewCapacity, int maxCapacity) { | ||
return allocator.calculateNewCapacity(minNewCapacity, maxCapacity); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any thoughts on making this a bit more generic? Something like
BufferPreferenceAllocator
that can be initialized with a boolean of direct vs heap?Don't really have any use case yet for anything other than this ... maybe you can think of one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nmittler not sure if we should... Do you think it is useful in other cases as well ? If not I would prefer to keep it package-private and we can open up once we need too. WDYT ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meh ... it's fine as-is. Just a thought :)