Skip to content

Commit 7302e19

Browse files
KristofferCKristofferC
andauthored
avoid some overhead from Tar.jl when unpacking the registry (#4505)
Co-authored-by: KristofferC <[email protected]>
1 parent 101997e commit 7302e19

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/Registry/registry_instance.jl

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,29 @@ function validate_no_overlapping_ranges(
330330
return
331331
end
332332

333+
# Simplified tarball reader without path tracking overhead
334+
function read_tarball_simple(
335+
callback::Function,
336+
predicate::Function,
337+
tar::IO;
338+
buf::Vector{UInt8} = Vector{UInt8}(undef, Tar.DEFAULT_BUFFER_SIZE),
339+
)
340+
globals = Dict{String, String}()
341+
while !eof(tar)
342+
hdr = Tar.read_header(tar, globals = globals, buf = buf)
343+
hdr === nothing && break
344+
predicate(hdr)::Bool || continue
345+
Tar.check_header(hdr)
346+
before = applicable(position, tar) ? position(tar) : 0
347+
callback(hdr)
348+
applicable(position, tar) || continue
349+
advanced = position(tar) - before
350+
expected = Tar.round_up(hdr.size)
351+
advanced == expected ||
352+
error("callback read $advanced bytes instead of $expected")
353+
end
354+
return
355+
end
333356

334357
function uncompress_registry(compressed_tar::AbstractString)
335358
if !isfile(compressed_tar)
@@ -339,11 +362,9 @@ function uncompress_registry(compressed_tar::AbstractString)
339362
buf = Vector{UInt8}(undef, Tar.DEFAULT_BUFFER_SIZE)
340363
io = IOBuffer()
341364
open(get_extract_cmd(compressed_tar)) do tar
342-
Tar.read_tarball(x -> true, tar; buf = buf) do hdr, _
343-
if hdr.type == :file
344-
Tar.read_data(tar, io; size = hdr.size, buf = buf)
345-
data[hdr.path] = String(take!(io))
346-
end
365+
read_tarball_simple(x -> true, tar; buf = buf) do hdr
366+
Tar.read_data(tar, io; size = hdr.size, buf = buf)
367+
data[hdr.path] = String(take!(io))
347368
end
348369
end
349370
return data

0 commit comments

Comments
 (0)