Advertisement

Small Value Type Optimization

Started by April 25, 2022 09:59 PM
1 comment, last by WitchLord 2 years, 7 months ago

I was curious about some implementation details.

I guess that any value in AS in the end will be stored in a something like a tagged union with at least sizeof(void*) bytes, and I guess that a asOBJ_VALUE | asOBJ_POD registered type is managed by std::memcpy into and from uint8_t* heap allocated data.

But I have a lot of small types which could fit inside a void* so I was wondering if any kind of small object optimization is implemented so that it's copied directly aliased in the union so that a lot of allocations and deallocations are avoided, which could be really optimal in my scenario in which I move a lot of these values.

asOBJ_VALUE | asOBJ_POD can be allocated on the heap, context stack, or inside the script classes depending on the situation. If you don't register the opAssign method or copy constructor, then you're right that a straight memory copy will be done using memcpy.

There is currently no optimization to try to group multiple values so a single copy can be made.

If you have a particular case where you feel the performance is particularly bad, let me know and I'll take a look at what can be done.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement