nats.py icon indicating copy to clipboard operation
nats.py copied to clipboard

Inline protocol parser for improved throughput

Open caspervonb opened this issue 4 months ago • 0 comments

Replace the modular parse() function with chunk-based inline parsing in _read_loop. Reading 64KB chunks and parsing multiple messages per buffer avoids function call overhead on the hot path.

Handler signatures now accept bytes instead of str to defer decoding until necessary.

Subscriber throughput improves ~63% (295k to 480k msg/sec with pub/sub on CPython).

caspervonb avatar Nov 27 '25 10:11 caspervonb