From 9bfb0fed27ea5f47db5cbce86480bb85173eb7a7 Mon Sep 17 00:00:00 2001 From: Colin Godsey Date: Tue, 24 Mar 2015 17:04:10 -0500 Subject: [PATCH] direct ByteBuffer performance note via https://gist.github.com/colinrgodsey/9bc606d09d035ba2334c we discovered it was always faster to copy to a direct buffer when dealing with NIO. No concessions need be made for wrapping in-heap data. --- .../src/main/scala/akka/io/DirectByteBufferPool.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/akka-actor/src/main/scala/akka/io/DirectByteBufferPool.scala b/akka-actor/src/main/scala/akka/io/DirectByteBufferPool.scala index 6f80ec5883..224a1e5a57 100644 --- a/akka-actor/src/main/scala/akka/io/DirectByteBufferPool.scala +++ b/akka-actor/src/main/scala/akka/io/DirectByteBufferPool.scala @@ -19,8 +19,12 @@ trait BufferPool { * A buffer pool which keeps a free list of direct buffers of a specified default * size in a simple fixed size stack. * - * If the stack is full a buffer offered back is not kept but will be let for - * being freed by normal garbage collection. + * If the stack is full the buffer is de-referenced and available to be + * freed by normal garbage collection. + * + * Using a direct ByteBuffer when dealing with NIO operations has been proven + * to be faster than wrapping on-heap Arrays. There is ultimately no performance + * benefit to wrapping in-heap JVM data when writing with NIO. */ private[akka] class DirectByteBufferPool(defaultBufferSize: Int, maxPoolEntries: Int) extends BufferPool { private[this] val locked = new AtomicBoolean(false)