would Panda3d support Pypy in the future?

it would be great if we have more choices of methods of speeding up the app.
don’t know how hard it is to make that work.

My understanding it is (super near) impossible as panda3d is written in c++. It would take less time to profile one’s python code and rewrite the slow bits as a c or c++ module.

Indeed, panda makes it super easy to write c++ code to support your python code in the performance critical parts. Since most likely only small parts of your program are performance critical, it should be easy to move them to c++.

I’ve never had issue with Python game logic code performance .
Only times was when trying to decode megabytes of custom data formats, then a C++ code was compiled to a pyd file and imported like a usual Python module.

However, back then I didn’t know about Cython. It seems extremely easy, even more so if you aren’t comfortable with C++. panda3d.org/blog/panda3d-and-cython/
I’m surprised why Cython is not more popular or even why languages like Python do not allow to ,for example, declare a type of an object explicitly if one wishes to. Then the interpreter wouldn’t have to determine it in the realtime and just add appropriate error checks and messages. But back to the topic, give Cython a try. Pypy can’t be used with Panda. On top of that Pypy being as fast as it claims is getting close to being completed and adpoted at snail speed.

For this to happen, someone would have to write CFFI bindings for Panda3D.

PyPy is good for Python-only code, but I’m not convinced it performs well binding with C++ code. Someone would have to experiment with CFFI bindings and compare them to CPython+interrogate bindings in order to find out.

Another project to consider besides cython is nuitka, which translates pure Python code to C code (that still interfaces with the CPython runtime). It seemed to work with Panda last time Itried it. I haven’t done any performance comparisons, however. But it might be a good alternative to cython if you don’t want to have to code in cython’s dialect.

the reason i wish for something like pypy, is that my python code can be run without any modification.
i can program in C and ASM, and got an impression that, translating existing python code into other language is not too difficult, but if a function is not “established” ( little chance of being modified in future), i would be reluctant to do the translation :smiling_imp: . and writing new function or modifying function in python is much quicker than in other languages.
for a program in development, there are great chances of functions being modified, except something like matrix rotation, vector add/sub etc which are very well established.
i once tried translating some of my established functions into ASM, and tested performance gain. although my ASM code should contain little unnecessary operations, i got only improvements of several times at max, some functions even took longer to run than python code. later i found out it was the overhead of CTYPES that reduced the improvement. so i learned that, if a function is short (like several lines), it’s better to use python than calling a DLL.
i don’t know whether other interface (like CFFI) has much lower overhead than CTYPES, i would avoid to call a function in DLL if it’s short, better stay in python.
but generally speaking, longer functions have bigger chance of being modified in the future… you see the problem here.

i’m not saying pypy is absolutely a savior, as some of my programs even run slower in pypy than in cpython :open_mouth: . and the speed gain (if there is any) may not be worth the trouble (of the Panda3D dev team). i’m just researching. in fact, it’s not yet my priority, so i haven’t tried hard to make cython or c++ or nuitka work for me. things are evolving, when i truly need that, there may be new born solutions.
i believe Panda3D dev team will do whatever worthwhile to improve the performance too.

Most likely you will be able to reduce your performance issues to a few spots which are slow, because python is usually fast enough to do everything else. Panda does not uses ctypes, it allows you to compile your C++ code into a python-libary (.pyd/.so) so you can use it like a python module.

If you really get into some performance issues at some point, I am pretty sure you will be able to resolve them that way, and writing the problematic code in C++ will most likely be faster than running the python code in PyPy.

If I may, I would say that tobspr made a very nice tool (see here [url]Panda Module Builder]) to make the generation of the .pyd module very easy through Interrogate.

This tool avoids the pains to manually configure Interrogate and thus, as long as you know C++, allows you to quickly generate the module.

i totally agree to what everybody said here.
just that , right now i am doing prototype/research rather than a product. C/C++ should be used in a massive game. python is better for prototyping , especially for a non-professional coder.

just tested Nuitka on the most complicated module of myself. the compiled module seemed to run correctly, and the time of each frame is reduced to about 80% . it’s a good start. except that the compiling is very slow. :stuck_out_tongue: