Contraz / demosys-py

A light high performance modern OpenGL 3.3+ Python Framework https://demosys-py.readthedocs.io/
ISC License
64 stars 5 forks source link

Figure out a way to speed up matrix operation in python #19

Open einarf opened 6 years ago

einarf commented 6 years ago

From #18

We are currently using pyrr for matrix operations. The main problem with pyrr is that it crates new instances for every calculation allocating a new ndarray. This is very expensive.

As an example: https://github.com/adamlwgriffiths/Pyrr/blob/a86968b7ed242017247e27ac8a0e7b84bca0c333/pyrr/matrix44.py#L223-L236

numpy.dot has an out parameter to store the result in an existing ndarray. This avoids memory allocation.

einarf commented 6 years ago

We should possibly also try to make the default dtype of matrix types ti be a 32 bit float as these can be converted directly into uniforms with tobytes.

Numpy:

The default depends on your system. On a 64-bit system, default types will be 64-bit. On a 32-bit system, default types will be 32-bit. There is no way to change the default short of re-compiling numpy with a different system C header.

This could mean we have to do something about pyrr.

einarf commented 6 years ago

A branch matrix-performance was crated for this. Managed to boost performance by 10% ish by doing some simple tweaks with a local branch of pyrr. It's unlikely that using pyrr will ever be efficient when drawing complex scenes. Might want to turn a solution in ModernGL for this.

einarf commented 6 years ago

This looks like the solution: https://github.com/cprogrammer1994/miniglm