Open zhiyangyou opened 1 year ago
Thanks, those are some great suggestions. Ideally, the allocator could be self-defined, so one could e.g. use a bump allocator for loading skeletons, which would significantly cut the number of mallocs.
Thanks, those are some great suggestions. Ideally, the allocator could be self-defined, so one could e.g. use a bump allocator for loading skeletons, which would significantly cut the number of mallocs.
bump allocator , this is an excellent suggestion for me! ^_^,thanks a lot !
I am a newbie in c++ :( , can you please recommend 1 such allocator to me.
I don't know of any 3rd party libraries for that I'm afraid.
I have noticed the SpineExtension class, but I don't know how to introduce some high-performance allocators to avoid some memory fragmentation. I don't know how other applications integrate the spine-cpp runtime library.
:( I checked a lot of blogs and they told me that malloc calls can only be minimized, not avoided. Ask if there is a better deal for me..
Do you think it's a good idea to encapsulate the deallocate and allocate methods of std::allocator, and add some cookie information to the header of the requested memory block?
I don't see how that'd help. Implementing a bump allocator that can beat malloc as we use it now is not hard. The issue is with object life times. A first step would be for anything allocated during loading of SkeletonData
via SkeletonJson
or SkeletonBinary
to be allocated by a bump allocator, while any other object type like Skeleton
uses malloc. This requires some refactoring of the runtime. There are a lot of reallocations happening during parsing of data, which doesn't lend itself well to bump allocation. I'm afraid there's no simple, immediate fix for this.
Ok, my doubt is gone, thanks for your reply. :)
Thanks to the spine-cpp runtime, it solved a performance hotspot in my game.
‘setAnimation ’causes a lot of memory request calls AnimationState::computeHold will result in a call to _propertyIDs.addAll(), which will result in a large number of Entry objects being created in HashMap, is it possible to selectively pool Entry objects to reduce malloc caused by setAnimation https://github.com/EsotericSoftware/spine-runtimes/blob/b1d5e7727d7cb61e1328a40218dab21f59dfbb87/spine-cpp/spine-cpp/src/spine/AnimationState.cpp#L1027
‘Animation’ Ctor, it would be better to change the left-value to a reference
https://github.com/EsotericSoftware/spine-runtimes/blob/b1d5e7727d7cb61e1328a40218dab21f59dfbb87/spine-cpp/spine-cpp/src/spine/Animation.cpp#L47
Implicitly calls the constructor of spine::String https://github.com/EsotericSoftware/spine-runtimes/blob/b1d5e7727d7cb61e1328a40218dab21f59dfbb87/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp#L353
use spine::String ( xxx, true) ctor and spine::String::unown() avoid temp string data copy and memory alloc
such as :
https://github.com/EsotericSoftware/spine-runtimes/blob/b1d5e7727d7cb61e1328a40218dab21f59dfbb87/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp#L527
https://github.com/EsotericSoftware/spine-runtimes/blob/b1d5e7727d7cb61e1328a40218dab21f59dfbb87/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp#L828