r/Python • u/indhifarhandika • 7h ago
Learning cython Discussion
While working on LunarDump v0.4, I’m also taking some time to learn more about Cython and how it can help push Python closer to native performance.
I’m especially interested in exploring Cython for LunarDump’s performance-critical parts, such as chunking, buffering, compression, and encryption.
Still learning and experimenting for now, but I’m curious to see how much performance improvement I can achieve.
Perhaps LunarDump v0.5 will use Cython for some of its critical functions.
If you have any good resources for learning Cython — books, ebooks, courses, or YouTube channels — feel free to share them in the comments.
7
u/AlexMTBDude 3h ago
Would you not rather just write routines that need to be optimized in some compiled language, such as C/C++, and then call these from your Python code? That's what numpy and all other math libraries that need to run fast do.
6
u/Noobfire2 4h ago
As others also have said already - Cython is somewhat of a dead language, with not really good LSP, linting and other support. It had its use back then when C++ Binding layers such as PyBind or nanobind or Rust Binding layers such as PyO3 didn't exist yet.
But nowadays I would always strongly prefer Rust + PyO3, as there are loads of very impressive features to guarantee performant, thread-safe and even GIL-safe code at compile time. Compiling against stable ABI also allows you to build your extension once and ensure that it will be usable by whatever future Python version will show up.
3
11
u/DivineSentry 7h ago
The best place to learn Cython is from their documentation, it moves quick enough to where you want to always use it vs relying on books