Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass functions by "reference" to bis event handlers #4898

Merged
merged 3 commits into from
Feb 14, 2017
Merged

Conversation

PabstMirror
Copy link
Contributor

Thanks to a discovery from @dedmen (ref CBATeam/CBA_A3#588)

Passing a large code function to a BIS EH has a significant performance cost.

Using interact_menu as an example.

addMissionEventHandler ["Draw3D", {x3 = diag_tickTime}];
for "_index" from 1 to 2000 do {
    // addMissionEventHandler ["Draw3D", FUNC(render)]; // (660 ms / 2000) = .33 ms
    addMissionEventHandler ["Draw3D", {call FUNC(render)}]; // (28 ms / 2000) = 0.014 ms
};
addMissionEventHandler ["Draw3D", {diag_log text format ["2000 calls took %1 ms", 1000 * (diag_tickTime - x3)]}];

So an extra processing time of ~0.3 ms when passing the entire function vs passing a short bit of code that calls the function.

@PabstMirror PabstMirror added ignore-changelog Release Notes: Excluded kind/optimization Release Notes: **IMPROVED:** labels Feb 14, 2017
@PabstMirror PabstMirror added this to the 3.9.1 milestone Feb 14, 2017
commy2
commy2 previously requested changes Feb 14, 2017
Copy link
Contributor

@commy2 commy2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look right.

_player setVariable [QGVAR(firedEH), _firedEH];
private _explosionEH = _player addEventHandler ["Explosion", LINKFUNC(explosionNear)];
private _explosionEH = _player addEventHandler ["Explosion", {call (explosionNear)}];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@@ -60,9 +60,9 @@ GVAR(lastPlayerVehicle) = objNull;
};
// Don't add a new EH if the unit respawned
if ((_player getVariable [QGVAR(firedEH), -1]) == -1) then {
private _firedEH = _player addEventHandler ["FiredNear", LINKFUNC(firedNear)];
private _firedEH = _player addEventHandler ["FiredNear", {call (firedNear)}];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@@ -35,7 +35,7 @@ GVAR(lastPlayerVehicle) = objNull;
TRACE_2("removed veh eh",_firedEH,GVAR(lastPlayerVehicle));
};
if ((!isNull _vehicle) && {_player != _vehicle}) then {
private _firedEH = _vehicle addEventHandler ["FiredNear", LINKFUNC(firedNear)];
private _firedEH = _vehicle addEventHandler ["FiredNear", {call (firedNear)}];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@dedmen
Copy link
Contributor

dedmen commented Feb 14, 2017

For reference: https://feedback.bistudio.com/T123355

@PabstMirror PabstMirror merged commit dfca4fd into master Feb 14, 2017
@PabstMirror PabstMirror deleted the bisEh branch February 14, 2017 16:54
thojkooi pushed a commit that referenced this pull request Mar 13, 2017
* Pass functions by "reference" to bis event handlers

* Add Doc

* Fix

Conflicts:
	addons/laserpointer/XEH_postInit.sqf
@PabstMirror PabstMirror removed the ignore-changelog Release Notes: Excluded label Mar 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/optimization Release Notes: **IMPROVED:**
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants