Not sure if this would be an optimization or not, but it theoretically sounds like a nice idea anyway, at least.
matrix.c:
https://github.com/berylline/compiz/blob/master/src/matrix.c
compiz-core.h(where the functions in the above source file have header definitions):
https://github.com/berylline/compiz/blob/master/include/compiz-core.h#L3266
linmath.h:
https://github.com/datenwolf/linmath.h/blob/master/linmath.h