Skip to content

perf: fewer syscalls, copies and allocations on I/O paths (2.4.0) - #3

Merged
kauri-off merged 1 commit into
masterfrom
io-perf
Oct 13, 2026
Merged

kauri-off merged 1 commit into
masterfrom
io-perf

Conversation

@kauri-off

Copy link
Copy Markdown
Owner

Additive, non-breaking performance pass; bumps to 2.4.0.

  • Syscalls: VarInt/VarLong are encoded into a stack buffer and written with a single call instead of one write per byte. New public encode(). read_sync/read_async docs now recommend wrapping sockets in a BufReader.
  • Copies: RawPacket::read_* no longer zero-fill before reading; uncompress reuses the inflated buffer for the payload; new consuming RawPacket::into_uncompressed avoids copying uncompressed bodies.
  • Allocations: compress_zlib / decompress_zlib_limited reuse per-thread deflate/inflate state and drop the extra 32 KiB BufReader; Vec<T> preallocation is capped at 64 KiB by bytes, not 4096 elements.
  • New: ByteArray, wire-compatible with Vec<u8> but read/written in bulk; CFB8 encrypt_in_place/decrypt_in_place; sync Cfb8WriteHalf reuses its scratch buffer.
  • Truncated zlib streams in decompress_zlib_limited now return an error.

Tests: new tests/bulk_io.rs plus compression tests (into_uncompressed parity, truncated stream, repeated state reuse). The trybuild snapshot changes only because ByteArray now shows in the implementors list.

Locally verified: all 8 feature combinations with -D warnings, clippy, fmt, MSRV 1.89, nightly docs.

🤖 Generated with Claude Code

- VarInt/VarLong encode on the stack and write in one call; add `encode()`
- RawPacket reads no longer zero the buffer first
- uncompress reuses the inflated buffer; add consuming `into_uncompressed`
- zlib compress/decompress reuse per-thread state, no 32 KiB BufReader
- add `ByteArray` for bulk VarInt-prefixed bytes
- cap Vec<T> preallocation by bytes instead of element count
- CFB8 `encrypt_in_place`/`decrypt_in_place`; sync write half reuses its buffer

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kauri-off
kauri-off merged commit 4730d47 into master Oct 13, 2026
10 checks passed
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