Faster structures for static targets
tbrosman opened this issue · 1 comments
tbrosman commented
Abstracts are extremely slow on the CPP targets (30x slower in some cases, see 7de5f63 for the test cases I used):
Class: test.TestStress TestStress.hx:9: Vector2 dot product
TestStress.hx:37: abstracts = 0.3588023
TestStress.hx:38: direct = 0.0624004
TestStress.hx:39: abstracts / direct = 5.75
.TestStress.hx:44: Matrix3x3 matrix product
TestStress.hx:103: abstracts = 0.468003
TestStress.hx:104: direct = 0.0156001
TestStress.hx:105: abstracts / direct = 30
This is due to the fact that the CPP target treats the inner type as a Dynamic. For example, the Matrix2x2 code for multiplyVector
:
public static inline function multiplyVector(m:Matrix2x2, v:Vector2):Vector2
{
return new Vector2(
m.a * v.x + m.b * v.y,
m.c * v.x + m.d * v.y);
}
Becomes:
Dynamic Matrix2x2_Impl__obj::multiplyVector( Dynamic m,Dynamic v){
HX_STACK_FRAME("hxmath.math._Matrix2x2.Matrix2x2_Impl_","multiplyVector",0x1b061ffc,"hxmath.math._Matrix2x2.Matrix2x2_Impl_.multiplyVector","hxmath/math/Matrix2x2.hx",117,0x43e15fa3)
HX_STACK_ARG(m,"m")
HX_STACK_ARG(v,"v")
HX_STACK_LINE(117)
return ::hxmath::math::_Vector2::Vector2_Impl__obj::_new(((m->__Field(HX_CSTRING("a"),true) * v->__Field(HX_CSTRING("x"),true)) + (m->__Field(HX_CSTRING("b"),true) * v->__Field(HX_CSTRING("y"),true))),((m->__Field(HX_CSTRING("c"),true) * v->__Field(HX_CSTRING("x"),true)) + (m->__Field(HX_CSTRING("d"),true) * v->__Field(HX_CSTRING("y"),true))));
}
tbrosman commented
Structures have changed significantly and are now much faster on static targets.