Skip to content

Optimize network reads in the session to generate a contiguous bytearray#195

Open
TheDistributor wants to merge 1 commit into
masterfrom
mgallwey/accelerate-network-io
Open

Optimize network reads in the session to generate a contiguous bytearray#195
TheDistributor wants to merge 1 commit into
masterfrom
mgallwey/accelerate-network-io

Conversation

@TheDistributor

@TheDistributor TheDistributor commented Jun 29, 2026

Copy link
Copy Markdown

Streamline the data-ingestion pipeline and outbound parameter encoding loop by eliminating high-overhead memory copies, optimizing primitive type comparisons, and increasing TCP window throughput.

Detailed changes:

  • session: Request an opportunistic 1 MiB socket receive buffer (SO_RCVBUF) to minimize fragmented kernel reads across heavy wire payload streams.
  • session: Rewrite __readFully to pre-allocate a single message-sized bytearray. Populate it directly using zero-copy sock.recv_into() on a slicing memoryview, replacing an iterative chunk concatenation loop.
  • encodedsession: Update recv() and input stream targets to return and use raw mutable bytearray buffers directly, cutting down an extra copy.
  • encodedsession: Refactor putValue to use rapid pointer-level exact type comparisons (type(v) is X) for common database primitives (int, str, float, bool) before falling back to heavier hierarchy-aware isinstance() checks for the long tail.

No performance change on its own, but lays the groundwork for other changes.

Streamline the data-ingestion pipeline and outbound parameter encoding loop by
eliminating high-overhead memory copies, optimizing primitive type comparisons,
and increasing TCP window throughput.

Detailed changes:
- session: Request an opportunistic 1 MiB socket receive buffer (SO_RCVBUF) to
  minimize fragmented kernel reads across heavy wire payload streams.
- session: Rewrite `__readFully` to pre-allocate a single message-sized
  bytearray. Populate it directly using zero-copy `sock.recv_into()` on a
  slicing memoryview, replacing an iterative chunk concatenation loop.
- encodedsession: Update `recv()` and input stream targets to return and use
  raw mutable bytearray buffers directly, cutting down an extra copy.
- encodedsession: Refactor `putValue` to use rapid pointer-level exact type
  comparisons (`type(v) is X`) for common database primitives (int, str, float,
  bool) before falling back to heavier hierarchy-aware `isinstance()` checks
  for the long tail.
@TheDistributor TheDistributor self-assigned this Jun 29, 2026
@TheDistributor TheDistributor changed the title Optimize network I/O buffering and parameter type dispatch Optimize network reads in the session to generate a contiguous bytearray Jun 29, 2026
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