You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The goal of this issue is to agree on basic design principles and expectations from this refactoring.
Goals
Speed up critical places in query processing by skipping bound checks, which ByteBuffer always performs when making any read or write. Bound checks could be hoisted outside the hot loops manually or enabled via assertions/static final boolean flag, that is effectively free with some precautions.
Memory object is immutable. "position and limit", if needed, are passed along with Memory as two primitive longs.
Upon creation a mutable Memory object has a cached immutable "view" object (which implements read methods and throws exception from write methods), this object is always returned when "as read only" is needed.
Explicit close() or free() on Memory is possible, but not strictly required, there is a sun.misc.Cleaner safety net, as well as in DirectByteBuffer.
While transition from ByteBuffer to Memory is in progress (not expected to be done all at once, but subsystem by subsystem, class by class see Move from ByteBuffer to Memory #3892 (comment)), and also when we need to interop with external libraries which require ByteBuffer, conversion from Memory to ByteBuffer and vice versa is possible. Likely it requires to
Use DirectByteBuffer-compatible format of Cleaner inside Memory
+ "Global" (immutable) Memory's bounds are checked optionally via assertions/guarded by static final boolean flag, "local" position and limit are check explicitly manually, with helper methods or versions of read and write methods of Memory, which accept read/write position and "local" limits. Move from ByteBuffer to Memory #3892 (comment)
The goal of this issue is to agree on basic design principles and expectations from this refactoring.
Goals
ByteBufferalways performs when making any read or write. Bound checks could be hoisted outside the hot loops manually or enabled via assertions/static final boolean flag, that is effectively free with some precautions.longindexes. See Removing Integer.MAX column size limit. #3743.Memoryobject has to be "sliced", "converted to read-only", etc. See define new high-level abstract storage interfaces with a default mmap implementation #3716 (comment).Design
It is moved to Druid source tree, not used as a dependency.See Move from ByteBuffer to Memory #3892 (comment)Memoryobject is immutable. "position and limit", if needed, are passed along withMemoryas two primitive longs.Memoryobject has a cached immutable "view" object (which implements read methods and throws exception from write methods), this object is always returned when "as read only" is needed.close()orfree()onMemoryis possible, but not strictly required, there is asun.misc.Cleanersafety net, as well as inDirectByteBuffer.ByteBuffertoMemoryis in progress (not expected to be done all at once, but subsystem by subsystem, class by classsee Move from ByteBuffer to Memory #3892 (comment)), and also when we need to interop with external libraries which requireByteBuffer, conversion fromMemorytoByteBufferand vice versa is possible. Likely it requires toDirectByteBuffer-compatible format ofCleanerinsideMemoryDirectByteBufferconstructors viaMagicAccessorImpl.Memory's bounds are checked optionally via assertions/guarded by static final boolean flag, "local" position and limit are check explicitly manually, with helper methods or versions of read and write methods of Memory, which accept read/write position and "local" limits. Move from ByteBuffer to Memory #3892 (comment)Objections, additions, corrections, questions are welcome.
@leerho @cheddar @weijietong @akashdw @himanshug @fjy @niketh