Poor performance when reading primitive types that aren't UInt8?
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- julia
- Domain
- performance
Research direction
Reproduce the allocation difference in the reported reader() MWE using TranscodingStreams.NoopStream, comparing read(io, Int32) with read(io, UInt8). Trace the read entry points involved in primitive-type reads and confirm that the completed work removes the per-call allocation without regressing the existing UInt8 behavior.
Written by the indexing model from the issue text.
Description
I am trying to read some data in a looping way, reading a mix of primitive types. Here's a simple MWE where I am just reading Int32s:
import TranscodingStreams
function writer()
open(joinpath(homedir(), "test.dat"), write=true) do io
write(io, rand(Int32, 1_000_000))
end
end
function reader()
open(TranscodingStreams.NoopStream, joinpath(homedir(), "test.dat")) do io
for i in 1:1_000_000
read(io, Int32)
# read(io, UInt8)
end
end
end
writer()
reader()
julia> @time reader()
0.025751 seconds (1.00 M allocations: 15.276 MiB)
This produces an allocation per read call, which becomes very slow in a tight loop! Reading 4 million UInt8s (see commented out line) has effectively zero allocations in the loop.
Is this expected behavior? Is my use-case uncommon? It does not seem to be specific to the NoopStream, since I first encountered it with the CodecZstd.ZsdtDecompressorStream.
Thanks.
- Dominant language
- Julia
- Stars
- 90
- Forks
- 26
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaIO/TranscodingStreams.jl
-
Allow generic `DenseVector{UInt8}` as input/outputPossibly taken @nhz2 claimed this 460 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 45/100
JuliaIO/TranscodingStreams.jl#247 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
JuliaIO/TranscodingStreams.jl#246 · 1 comment ·
-
Support libaec?Open
Difficulty 3/5 1-2 days Newbie friendliness 25/100
JuliaIO/TranscodingStreams.jl#207 · 2 comments ·
-
API for BufferOpen
Difficulty 5/5 Over a week Newbie friendliness 35/100
JuliaIO/TranscodingStreams.jl#202 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
JuliaIO/TranscodingStreams.jl#188 ·
All issues in JuliaIO/TranscodingStreams.jl
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
-
question
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
brown-ccv/Chamber.jl#272 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
JuliaAstro/SolarPosition.jl#143 ·
-
distributions
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
JuliaBayes/Wren.jl#404 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
JuliaAI/MLJTransforms.jl#113 ·
Maintainers usually reply within 1 day