1

I have a pure-Python module that compiles with Cython into .so, for performance.

The project currently uses Python 3.8 and everything works fine.

I've read CPython 3.11 comes with potentially great performance benefits, so I'm wondering the cost/benefit effort of upgrading.

Do any of the CPython 3.11 optimizations translate to Cython-compiled code? Which ones? How much?

What is the expected overall effect of Cython on 3.11 relative to 3.8 code?

dippas
  • 58,591
  • 15
  • 114
  • 126
Mark Scott
  • 21
  • 3
  • 1
    I've voted to reopen because I think this is actually pretty clear and well-scoped. The optimizations in Python 3.11 were applied to a relatively small number of areas and it's relatively easy to work out how they'll interact with Cython. – DavidW Dec 15 '22 at 18:37

1 Answers1

1

Basically none of it.

  • Start-up applies to starting the interpreter (before you load any Cython modules)
  • "Cheaper, lazy Python frames" - Cython doesn't create frames (apart from when an exception is raised, and even then I doubt it applies)
  • "Adaptive interpreter" is for interpreted code. It specializes bytecode based on past results - so if an attribute lookup bytecode instruction in a certain function turns out to be looking up in a class, it assumes the same will apply next time. Since Cython doesn't use bytecode, these optimizations just don't apply. (However, if you've applied static types correctly then Cython may be doing similar optimizations already)

As ever, if you're really interested then you should measure it. But I wouldn't expect many benefits to Cython code

DavidW
  • 29,336
  • 6
  • 55
  • 86