nats.py
nats.py copied to clipboard
Inline protocol parser for improved throughput
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).