HaxeFoundation / hxcpp

Runtime files for c++ backend for haxe
Other
297 stars 189 forks source link

Faster CFFI Calls #1139

Closed NeeEoo closed 2 months ago

NeeEoo commented 2 months ago

Its not needed to load the function every time, so its better to make it only load once

SomeGuyWhoLovesCoding commented 2 months ago

I'm definitely adding this to my modified hxcpp

hughsando commented 2 months ago

I think the function should only get loaded once. The idea is that "name" (the function you are calling) starts as function pointer, pointing to the "IMPL_" function which is actually a loader function. So name should never theoretically start as the null pointer (barring static order initialization issues). The loader function overwrites the "name" function pointer to point the real version, so subsequent calls will go straight to the real function and do not even need to try loading again. I print statement should verify if this is working correctly.

NeeEoo commented 2 months ago

I think the function should only get loaded once. The idea is that "name" (the function you are calling) starts as function pointer, pointing to the "IMPL_" function which is actually a loader function. So name should never theoretically start as the null pointer (barring static order initialization issues). The loader function overwrites the "name" function pointer to point the real version, so subsequent calls will go straight to the real function and do not even need to try loading again. I print statement should verify if this is working correctly.

Yea that would likely work! I'll work on implementing it soon

NeeEoo commented 2 months ago

Closing this, since i noticed it broke compiling with lime somehow. If someone figures out a fix please tell me (val_string call in Font.fromFile caused issues, probs calling from a stale reference)