Common - Improve performance of zero-delay PerFrameHandlers - #1852
Open
LinkIsGrim wants to merge 2 commits into
Open
Common - Improve performance of zero-delay PerFrameHandlers#1852LinkIsGrim wants to merge 2 commits into
LinkIsGrim wants to merge 2 commits into
Conversation
PabstMirror
reviewed
Aug 23, 2026
PabstMirror
reviewed
Aug 23, 2026
| // Execute per frame handlers | ||
| { | ||
| if (diag_tickTime > (_x select 2)) then { | ||
| _x params ["_function", "_delay", "_delta", "", "_args", "_handle"]; |
Contributor
There was a problem hiding this comment.
they shouldn't be
but I would hate if some func is expecting _args or _handle to exist
Contributor
Author
There was a problem hiding this comment.
wiki examples are explicit: https://github.com/CBATeam/CBA_A3/wiki/Per-Frame-Handlers#examples
bad code'll break I guess?
PabstMirror
approved these changes
Aug 23, 2026
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When merged this pull request will:
remove,getandsetinstead of indexing from the end of the array.Handles' indexes can now be negative. handle index >= 0 -> tracked in perFrameHandlerArray. handleIndex <= -1 -> eachFrameHandlerArray. Macros
PFH_EACHFRAME_(ENCODE|DECODE)andPFH_IS_EACHFRAMEfor handling this, though they're just wrappers around negative conversion/x < 0check.Zero-delay PFHs avoid
paramsand just_x selectwhatever they need.Delayed PFHs keep same behavior otherwise.
Note:
CBA_fnc_addPerFrameHandlerwill still never return negative values. Negatives are internal.Benchmark
Note this is synthetic: the loop bodies are the real ones, including the call and the ETA write, but the handler payload is empty and the hit/miss mix is fixed, so the differences are loop overhead only.
diag_codePerformance, 40 handlers per array, 10000 cycles, empty payload so thecallcost is present in every variant. "hit" is a handler that fires this frame.params, then check)params)select, no check)paramsSo a zero delay handler costs about 62% less overhead than it does today. For reference, the cost #1835 added on the hit path turns out to be about 2.5% once the
calland the ETA write are in the measurement, and it remains a large win on the miss path, so this is not a regression fix - it is a straight speedup for handlers that run every frame.Execution order
Behavior change here. Zero-delay PFHs will get executed after all delayed PFHs instead of in registration order among them. We don't document any ordering guarantees and I don't think it'll cause an issue, but bad code (PFHs mutating each other) may behave differently in terms of execution order. Also, giving a PFH a delay after registration moves it to the end of perFrameHandlerArray. Changing the delay of an already-delayed PFH still leaves it in place.