The Haxe manual says that using strucure on a static target has an impact on performance.
So I tried this little example on HL/C to measure it:
typedef Point = {
var x : Int;
var y : Int;
}
class Main {
static function main() {
var p1:Point = {x:12, y:23};
var p2:Point = {x:42, y:7};
var dx = p1.x - p2.x;
var dy = p1.y - p2.y;
trace(dx*dx + dy*dy);
}
}
The hashlink compiled code to C gives this result:
int r0, r2, r3, r4, r5, r6, r7, r10;
r0 = 12;
r2 = 23;
r3 = 42;
r4 = 7;
r5 = r0 - r3;
r6 = r2 - r4;
r9 = (haxe__$Log)g$_haxe_Log;
r8 = r9->trace;
if( r8 == NULL ) hl_null_access();
r7 = r5 * r5;
r10 = r6 * r6;
r7 = r7 + r10;
I don’t see any performance penalty, or dynamic lookup as stated in the manual.
Did I miss something? Or does my example is too basic? Or does the performance impact is only related to the compilation and not the runtime?