Skip to content

Conversation

@v0y4g3r
Copy link

@v0y4g3r v0y4g3r commented Nov 21, 2025

Changes

Specifically handle input than fits into one cache line, find out last non-continuation indicator and calculate the deserialized data size, we can also avoid reallocations.

Also add some roundtrip tests to assert correctness.

image
$ cargo bench  --bench 'serde' -- 'read_bytes' 
     Running benches/serde.rs (target/release/deps/serde-358374367734b2ff)
read_bytes/size-10      time:   [17.310 ns 17.408 ns 17.526 ns]
                        change: [-47.367% -47.052% -46.716%] (p = 0.00 < 0.05)
                        Performance has improved.

read_bytes/size-10-reverse
                        time:   [18.816 ns 19.252 ns 19.801 ns]
                        change: [-43.694% -41.106% -38.353%] (p = 0.00 < 0.05)
                        Performance has improved.

read_bytes/size-20      time:   [19.293 ns 19.390 ns 19.494 ns]
                        change: [-67.566% -67.285% -67.014%] (p = 0.00 < 0.05)
                        Performance has improved.

read_bytes/size-20-reverse
                        time:   [21.318 ns 21.457 ns 21.630 ns]
                        change: [-63.823% -63.175% -62.320%] (p = 0.00 < 0.05)
                        Performance has improved.

read_bytes/size-50      time:   [35.937 ns 36.147 ns 36.402 ns]
                        change: [-57.527% -57.064% -56.471%] (p = 0.00 < 0.05)
                        Performance has improved.

read_bytes/size-50-reverse
                        time:   [36.077 ns 36.240 ns 36.426 ns]
                        change: [-66.473% -66.063% -65.710%] (p = 0.00 < 0.05)
                        Performance has improved.

 feat: expose `read_bytes` and add benchmark for deserialization

 - make `Deserializer::read_bytes` public
 - add `read_bytes` benchmark covering normal & reverse encoding

Signed-off-by: Lei, HUANG <[email protected]>
 perf: optimize `read_bytes` with fast-path and zero-copy chunking
 - Add `read_bytes_fast` that avoids per-byte copies

Signed-off-by: Lei, HUANG <[email protected]>
 refactor: unify bytes deserialization paths and add reverse-mode tests

 - merge read_bytes() into read_bytes_fast() to handle both normal and flip modes
 - remove obsolete copy_to_slice helper
 - add comprehensive roundtrip tests for reverse/flip encoding
 - simplify lifetime bounds in serde impls
 - use is_multiple_of for clarity in decimal serialization

Signed-off-by: Lei, HUANG <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant