-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance issues when reading multiple packed structures #13
Comments
I updated and reduced the gist above a little: using BenchmarkTools
using StructIO
const io = IOBuffer(zeros(UInt8, 16*1000));
abstract type TwoUInt64s end
@io struct TwoUInt64sDefault <: TwoUInt64s
x::UInt64
y::UInt64
end align_default
@io struct TwoUInt64sPacked <: TwoUInt64s
x::UInt64
y::UInt64
end align_packed
function read_written_out(io::IOBuffer, t::Type{<:TwoUInt64s})
x = read(io, UInt64)
y = read(io, UInt64)
t(x, y)
end
println("Using read_written_out:")
@btime read_written_out($io, TwoUInt64sPacked) setup=seekstart($io)
println("Using StructIO Default:")
@btime unpack($io, TwoUInt64sDefault) setup=seekstart($io)
println("Using StructIO Packed:")
@btime unpack($io, TwoUInt64sPacked) setup=seekstart($io) Which gives:
StructIO allocates here on every I'm not sure if the current general |
Couldn't And/or maybe you could have an |
I've encountered this in replacing manually written out read and write methods with StructIO in visr/LasIO.jl#10. Although using StructIO is elegant, it's also slower.
I've put up a gist here: https://gist.github.com/evetion/2b57d6105cca39b2d3c6ef670a5cc393 with the following results for reading a thousand TwoUInt64s.
The handwritten read version, which also can be generated, is ~200 times faster.
I know this is an unfair comparison, as StructIO has much more functionality than these simple read functions, but it seems it could be faster, especially if you look at the allocations, which are on par.
Let me know if you can't duplicate these results, or if I'm missing a StructIO method for reading multiple packed structures.
The text was updated successfully, but these errors were encountered: