Developers port Python's natsort to Rust, fix 45x slowdown after 133,000 fuzz tests
A development team porting Python's natural-sort library natsort to Rust initially produced a binary nearly four times slower than the interpreted Python original, traced to regex recompilation on every input item. Refactoring the code to compile the regex once per function call cut latency from roughly 900ms to 20ms, making the Rust port 11.8 times faster than Python on identical workloads. A subtle edge case emerged where Python treated bare tokens like 'nAn' as floating-point NaN values during sorting, while the Rust port handled them as plain text, requiring a rewrite of the component-splitting logic. Additional bugs — including a missing NUMAFTER sentinel for numeric-leading strings and an entirely unimplemented PRESORT flag — were uncovered through a custom Pytest bridge that ran the upstream Python test suite directly against the Rust port. After all fixes, the port passed 133,000-plus randomized fuzz inputs with zero mismatches and cleared the Python test suite with no failures.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in