open-contracting / software-development-handbook

A guide for developers of OCP's tools
https://ocp-software-handbook.readthedocs.io/en/latest/
Other
4 stars 1 forks source link

Explore PyPy, mypyc, Cython #113

Open jpmckinney opened 2 weeks ago

jpmckinney commented 2 weeks ago

Original description is from when issue was only about PyPy.

We do a fair bit of JSON deserializing (and serializing). On CPython, we use orjson. The json standard library on PyPy is slower, but not by a huge amount, so using PyPy could still be a performance gain. In principle, orjson could be made to support PyPy. https://github.com/ijl/orjson/issues/90#issuecomment-2380389948

Candidates with heavy processing:

Next steps

PyPy profiler support

If PyPy really is faster than CPython for our workloads, then there is no point profiling and optimizing on CPython. So, we'd need profilers on PyPy.

Supported

Memory

TBD

Not supported

Memory


Comparison and discussion: https://github.com/plasma-umass/scalene/issues/423

jpmckinney commented 2 days ago

PyPy disadvantages:

Useful review of other compilers, followed by mypyc content https://glyph.twistedmatrix.com/2022/04/you-should-compile-your-python-and-heres-why.html

These tools benefit from comprehensive (and narrow, i.e. few Any) typing. To add types, can try:

Other compilers:

Worth trying out PyPy and mypyc, as they can more or less work with existing code. Can still consider Cython in cases where the alternative is a full rewrite in Rust. Can try these on ocds-merge for learning.