HaxeFoundation / hxcpp

Runtime files for c++ backend for haxe
Other
294 stars 187 forks source link

Array<Entity> became as Array<::Dynamic> #589

Open posxposy opened 7 years ago

posxposy commented 7 years ago

var entities:Array<Entity> = new Array<Entity>(); where Entity is a regular Haxe class. This code is translated to: ::Array< ::Dynamic> entities = ::Array_obj< ::Dynamic>::__new();

And to get access to any element of that array Haxe generated this code: ::lib::entities::Entity e = entities->__get(i1).StaticCast< ::lib::entities::Entity >();

Would be nice to avoid this StaticCast and generate arrays as Array< ::Entity>;

I measured execution time for element access and here is what time I got.

StaticCast (generated by Haxe):                      3.10301402350888e-07
_hx_array_unsafe_get (using cpp.NativeArray):    0.0353070371420472
Removed StaticCast by hands:                         0.0411155711772153
hughsando commented 7 years ago

I'm not sure what these numbers are - the remove StaticCast is slower? The idea is that the static-cast should not actually generate any extra machine code in this case. The complexity is really only needed for getting elements from Arrays-of-Arrays, where the haxe typing system can't be trusted. I'm probably going to rewrite this soon, but any information would be good to take into account.

posxposy commented 7 years ago

I meant, that StaticCast is much slower than direct access to array element.

hughsando commented 7 years ago

As far as I know, the StaticCast should not change the machine code for all cases except where the element type itself is an array. Although, this would be worth verifying in the disassembly.

On Thu, Jun 8, 2017 at 5:29 PM, Dmitry Hryppa notifications@github.com wrote:

I meant, that StaticCast is much slower than direct access to array element.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HaxeFoundation/hxcpp/issues/589#issuecomment-307050457, or mute the thread https://github.com/notifications/unsubscribe-auth/ABlp1rRIvAV-PYUuzMwq3bjonmC3O4WDks5sB77_gaJpZM4M-McV .