Internal API to resolve a Callable
to CallableCustom*
, optimizing repeat call performance.
#11787
Labels
Callable
to CallableCustom*
, optimizing repeat call performance.
#11787
Describe the project you are working on
Godot performance.
Describe the problem or limitation you are having in your project
For a PR attempting to optimize
Array.filter
, I profiled repeatcallp
performance.In particular, it was interesting to see that manual
GDScript
array filtering was substantially faster thanArray.filter
. It would be possible to improveArray.filter
to close the gap.Digging into the profiler, considerable time was wasted on repeat
callp
preparation and validation:This could be optimized.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
It would be possible resolve
Callable
to a reference-ownedCallableCustom
.A function could be added like
CallableCustom *Callable::to_custom(CallError &r_call_error) const
. It would return aCallableCustom
, either new (refcount 1) or existing (refcounted incremented). The caller would hold on to it until finished with all calls. For repeat calls, this should eliminate the overhead for repeat calls, changing fromO(n)
toO(1)
.For single calls, this would be the same speed or slower than
callp
. Depending on the real performance difference, thecallp
interface could perhaps be eliminated to compensate for the increase in complexity.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
The function could be implemented easily like:
Object
would require a similar implementation, to resolve aStringName
to aCallableCustom
that is pre-injected with the relevantObject*
:RefCounted
, it would increase the reference count by 1 and assume the Object persists in memory, gaining similar speeds as otherCustomCallable
implementations.RefCounted
, theCustomCallable
would need to verify theObjectID
on each call. This would be slow (similar speed as currently) right now, but may be acceleratable in the future.GDScript could also make use of this API: If it is known within a function frame that a
Callable
isn't re-assigned, it could resolve toCustomCallable
on first call, and re-use the returned function pointer each repeat call. This should give it a similar boost as other callers.All in all, the proposed change should speed up repeat
callp
calls by an amortized 17%.Future projects could attempt to dig in further and re-use a call frame of
GDScriptFunction::call
for repeat calls, possibly improving performance further.If this enhancement will not be used often, can it be worked around with a few lines of script?
No.
Is there a reason why this should be core and not an add-on in the asset library?
It's core.
The text was updated successfully, but these errors were encountered: