[TEST] Cython performances test

Yeah, you’re right. You don’t need to be able to import a class to manipulate it’s objects.

Did some testing.
I am now 100% sure that importing module directly from the cython script crashes blender.
I am also 100% sure that passing whatever you want to the cython script will NOT crash blender.

In other words:

This works:


cdef int multiply(int val1, int val2):

    return val1*val2

def doIt(function):

    cdef int val1, val2

    gameObject = function().owner #function is bge.logic.getCurrentController()

    val1 = gameObject['Val1']
    val2 = gameObject['Val2']

    gameObject['result'] = multiply(val1, val2)

but not this:


import bge

cdef int multiply(int val1, int val2):

    return val1*val2

def doIt(function):

    cdef int val1, val2

    gameObject =  bge.logic.getCurrentController().owner

    val1 = gameObject['Val1']
    val2 = gameObject['Val2']

    gameObject['result'] = multiply(val1, val2)

No problems after all.

What happened with this?

I’m currently using Cython in a fairly involved manner, but not inside the bge, and not for performance: I’m trying to create a pythonic wrapper for certain C/C++ libraries.

I don’t think BGE programs can really benefit that much from Cython, because for most BGE programs, logic is not the bottleneck; As long as you can keep a steady framerate, it doesn’t matter how fast/slow the code actually runs.

So, don’t rush to needlessly complicate what could otherwise be a fairly simple system.

This is true to a certain extent. For my own project the logic usage can increment quite easily to above 1 ms with one client and no NPC players. I can envisage this drastically increasing with increase in clients (exponential roughly, without culling using relevancy criteria), NPCs, and more complex logic (although the 1ms is partially attributed to the system itself.) I’m considering writing the base network layer in cython as the looping is rather slow, and this is what’s using most of the time, alongside the overhead of method calls.