jam1garner / jam1garner/binrw

For a fixed-size struct, is it possible to read or write in a single operation?

Open
#348 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
853
Forks
56
PR merge metrics
No merged PRs in 30d

Description

I wrote a demo using binrw, and upon observing the read and write process, I found that for fixed-size structs, binrw always reads or writes the struct members one by one. This seems quite odd. In the case of a large number of structs, frequent reads or writes could impact performance.

Here is the demo code:

rust
#[binrw]
pub struct A {
a: u32,
b: [u8; 10],
}
This block of code should be able to be read or written in one go, but when I use a NoSeek-wrapped reader or writer to read or write, I observed that it first reads or writes the a in A, and then reads or writes the b in A.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the demo with struct A and a NoSeek-wrapped reader or writer, then inspect how binrw processes each field. Done means establishing whether a fixed-size struct can be read or written in one operation and verifying the resulting behavior against the reported performance concern.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.