raylib-python-cffi icon indicating copy to clipboard operation
raylib-python-cffi copied to clipboard

Pyray : convert function arguments based on c function signature

Open Lcbx opened this issue 3 years ago • 9 comments

Hi,

while testing the Pyray module I stumbled upon your comment about function calls using a lot of string comparisons at runtime, so here's an alternative that basically converts python arguments to the type expected by the c function.

Interestingly I have not found that great a performance improvement on the script I tested it on (~3%) but at least we don't inspect the c function at each call anymore.

keep being awesome !

Lcbx avatar Dec 15 '21 00:12 Lcbx

just found a bug using this.

some arguments expect pointers but can be given non ffi pointers ; however since signatures expects a pointer it calls ffi.addressof on the argument and crashes. Imma fix that.

Lcbx avatar Dec 15 '21 01:12 Lcbx

not the best fix but it works

Lcbx avatar Dec 15 '21 01:12 Lcbx

found a way to check on type rather than str(type)

should be robust and work with dynamic since the C_POINTER type we check is determined in pyRay init

Lcbx avatar Dec 15 '21 10:12 Lcbx

This looks like quite a major change so will probably take me a while to review it. Let me know when it’s finished anyway.

electronstudio avatar Dec 16 '21 15:12 electronstudio

The implementation change is around 15 loc, only in pyray/init.py other files are changes to examples

Lcbx avatar Dec 16 '21 18:12 Lcbx

oh yeah and it's pretty much finished afaik, tested it on a few examples (your pyrayTest, bunnyMark, boxCollisions and animation)

Lcbx avatar Dec 16 '21 18:12 Lcbx

Example is added, thanks. I had to add an unsigned int* to satisfy Raylib though,

electronstudio avatar Feb 03 '22 00:02 electronstudio

oh i see, you wrote a special case for that call to add the unsigned int*. i don't really want to be special casing anything.

electronstudio avatar Feb 03 '22 00:02 electronstudio

do you have a benchmark that shows a difference for the changes to pyray/init.py ?

electronstudio avatar Feb 03 '22 01:02 electronstudio