Skip to content

Commit 697df28

Browse files
committed
Pre-allocate buffer
If we let transcode to its own allocation it will allocate a small vector, start filling it, resize the vector, fill it some more, resize the vector, etc. Instead in this commit we pre-allocate a vector of the corect size and pass it to transcode(). Inspired by #399
1 parent c469151 commit 697df28

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
3333
SentinelArrays = "91c51154-3ec4-41a3-a24f-3f23e20d615c"
3434
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
3535
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
36+
TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
3637
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
3738
WorkerUtilities = "76eceee3-57b5-4d4a-8e66-0e911cebbf60"
3839

@@ -48,6 +49,7 @@ PooledArrays = "0.5, 1.0"
4849
SentinelArrays = "1"
4950
Tables = "1.1"
5051
TimeZones = "1"
52+
TranscodingStreams = "0.10"
5153
WorkerUtilities = "1.1"
5254
julia = "1.6"
5355

src/table.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,11 @@ function uncompress(ptr::Ptr{UInt8}, buffer, compression)
521521
len = unsafe_load(convert(Ptr{Int64}, ptr))
522522
ptr += 8 # skip past uncompressed length as Int64
523523
encodedbytes = unsafe_wrap(Array, ptr, buffer.length - 8)
524+
buf = Vector{UInt8}(undef, len)
524525
if compression.codec === Meta.CompressionTypes.LZ4_FRAME
525-
decodedbytes = transcode(LZ4FrameDecompressor, encodedbytes)
526+
decodedbytes = transcode(LZ4FrameDecompressor, encodedbytes, buf)
526527
elseif compression.codec === Meta.CompressionTypes.ZSTD
527-
decodedbytes = transcode(ZstdDecompressor, encodedbytes)
528+
decodedbytes = transcode(ZstdDecompressor, encodedbytes, buf)
528529
else
529530
error("unsupported compression type when reading arrow buffers: $(typeof(compression.codec))")
530531
end

0 commit comments

Comments
 (0)