Repository navigation
Frame packets without throwing on partial reads - #1552
Pix3lPirat3 wants to merge 1 commit into
Conversation
The splitter read each packet-length varint with protodef's readVarInt, which throws a PartialReadError when the buffer does not yet hold a complete varint. That happens on nearly every TCP segment (a packet split across reads), and the error's constructor captures a stack trace each time, which profiled as a top CPU cost under load (a chunk-streaming session spent ~8% there). Decode the length inline instead, returning null when more bytes are needed. Framing is byte-identical (added a splitter test covering byte-at-a-time and mid-varint boundaries); the deserializer still uses protodef normally.
rom1504
left a comment
There was a problem hiding this comment.
Astra agent review — AI-generated, not manually written by the maintainer.
Reviewed 49a5d57 using the review skills prismarine-protocol-data-review (stream fragmentation and framing semantics), prismarine-architecture-review (the allocation/error-path change), and prismarine-review (test discovery and existing feedback).
The four submitted fragmentation tests pass locally, and I found no blocker in their valid-frame behavior. There is one validation repair before calling this ready: none of these tests is selected by the current CI version filter, as detailed inline. Running the same file with -g 26.1v executes zero tests. I did not independently reproduce the performance benchmark.
|
|
||
| // The splitter reassembles length-prefixed packets from an arbitrarily chunked TCP stream. It must | ||
| // frame identically no matter how the bytes are delivered, including when a chunk boundary falls in | ||
| // the middle of a packet's length varint (the case the splitter must wait on rather than mis-frame). |
There was a problem hiding this comment.
Astra agent review — AI-generated, not manually written by the maintainer.
[P2] Include the version-independent splitter suite in CI
.github/workflows/ci.yml runs every test job as npm run mochaTest -- -g ${{ matrix.mcVersion }}v; the other job only runs lint. This suite's title has no version suffix, so its four new framing cases never run in any CI job. I confirmed 4 passing when executing this file normally and 0 passing with -g 26.1v.
Add an explicit unfiltered invocation of test/splitterTest.js to a required job (or a small version-independent test job), keeping the existing version matrix. These are appropriate focused tests of the real stream transform; they just need to be part of the maintained gate.
Skills used: prismarine-review and its repository testing standards caught the runner/filter mismatch; prismarine-protocol-data-review checked that the assertions exercise actual framing across chunk boundaries.
|
More numbers for this, from a load with many bots at once. A bot service ran N mineflayer bots on
Every sample of it comes from the splitter: It grows with the number of players, since each bot gets more small packets (other players' With this PR applied as a patch, the same load with 64 bots: With all bots in one thread the share is smaller (2.2% at 48 bots): a busy thread reads larger |
49a5d57 to
07cd1d1
Compare
The
Splitterreads each packet-length varint with protodef'sreadVarInt, which throws aPartialReadErrorwhen the buffer doesn't yet hold a complete varint. On a TCP stream that happens on nearly every segment (a packet split across reads), andPartialReadError's constructor captures a stack trace each time.Profiling a chunk-streaming session, that error construction was a top CPU cost:
ExtendableError/PartialReadErrorwas the #1 non-GC function (~7-8%), and all of it originated fromreadVarIntinsideSplitter._transform(never the deserializer, which only ever receives complete frames). Measured throw+catch cost ~9.8us each, almost entirely the stack capture.This decodes the length varint inline and returns
nullwhen more bytes are needed, so the hot framing loop no longer throws. Framing is byte-for-byte identical to before (verified against the old splitter across whole-stream, one-byte-at-a-time, fixed and random chunkings, incl. boundaries landing mid-length-varint); addedtest/splitterTest.jscovering those. With the change,PartialReadErrordisappears from the profile and protodef's CPU share on a chunk-load session dropped from ~11% to ~4%. The packet deserializer still uses protodef's throwing reads as before.