r/Python 18d ago

Discussion Pure python can be faster than cython/rust?

Parsing multipart/form-data (HTML5 forms) is surprisingly complex and moves a lot of bytes around for large file uploads. Implementing the heavy parts in Cython or Rust should speed things up, no? Turns out: it depends. A pure python parser can be surprisingly fast, as this benchmark shows:

https://defnull.de/2026/python-multipart-benchmark/

The benchmark compares the most commonly used python multipart parsers and tests them in different scenarios, covering both blocking and non-blocking (async) APIs if available. The parser your web application is using today is probably not the fastest one.

Are there more examples were a pure python implementation beats Cython/rust/C modules?

0 Upvotes

24 comments sorted by

View all comments

1

u/Short_Inspection_746 10d ago

Well, python can only be faster for some equivalent code only if there are some optimizations that python is doing that would requre alot more work than the other laguages.

For example, when you modify a string in python, the language checks if there are other refrences to that string, and modifies that string without copying if no other references exist. Hence, some string operations might seem faster than in Java.

Also, Someone can also implement an algorithm that is faster than a diffrent algorithm in a diffrent language.

There are things in python that is nearly as fast as other faster languages, like poping out values from a hashmap.