Closed duskmoon314 closed 2 months ago
Quickly wrote up a possible solution here: https://github.com/sharksforarms/deku/pull/441
EDIT: Eh, I need to fix the test failures.
I also wonder whether it is possible to read an exact number of bytes instead of the loop for Vec
. But I haven't figured out how to specialize the trait implementation for Vec over the generic Vec .
I think the solution here might just be the use a BufReaader
, which will read larger amounts at a time instead of one byte. Syscalls wise at least.
I just found that
read_all
seems to perform worse thancount
. So, I'm opening this issue to see whether there is room for improvement.The rust code I used to test is as follows. I defined two simple structs that only wrap
Vec<u8>
and use Deku to read[u8; 1500]
into these structs.The output of criterion:
The result shows that
read_all
takes nearly 14 times longer thancount
on my machine (CPU: x86-64 2.10GHz 80threads).Dig into the code:
The code is not very different; there is just one check,
count == 0,
and the other,reader.end()
. I wonder whetherreader.end()
can be improved to perform better.I also wonder whether it is possible to read an exact number of bytes instead of the loop for
Vec<u8>
. But I haven't figured out how to specialize the trait implementation forVec<u8>
over the genericVec<T>
.