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

FIX: Fixed a performance issue with many objects using multiple action maps [ISXB-573] #1951

Merged

Conversation

AlexTyrer
Copy link
Collaborator

@AlexTyrer AlexTyrer commented Jun 20, 2024

Description

Avoid costly (and pointless) iterations over all messages / objects / maps when we don't need to.

Issue: https://jira.unity3d.com/browse/ISXB-573

This codepath can be very expensive when there are a lot of messages to send to lots of objects with maps - much of the cost is in dereferencing handle.Target in DeferredResolutionOfBindings() which involves taking a mutex lock.

Further, once the lock is taken for each object, ResolveBindingsIfNecessary() is called for each of that object's InputActionMaps which in the general case does nothing (when there is nothing to do).

In the supplied (ridiculous to show the point) test project with 900 objects, each with 6 maps receiving 4500 mouse move messages this leads to:

  • over 21 million calls to ResolveBindingsIfNecessary() that do nothing
  • over 4 million mutex locks in resolving handle.Target in DeferredResolutionOfBindings()
  • frame times over 1 second!

Changes made

This change adds a static InputActionMap.s_NeedToResolveBindings that is set when we know that at least one InputActionMap has changes that need resolving. This is cleared when a resolve pass has been completed.

With this change the frame time in the example only increases by about 2-3ms when the mouse is moving.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • FogBugz ticket attached, example ([case %number%](https://issuetracker.unity3d.com/issues/...)).
    • FogBugz is marked as "Resolved" with next release version correctly set.
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

o Avoid costly (and pointless) iterations over all messages / objects / maps when we don't need to
@AlexTyrer AlexTyrer requested review from ekcoh and lyndon-unity June 20, 2024 10:13
@AlexTyrer AlexTyrer changed the title [InputSystem] Track need to resolve Action bindings (case ISXB-573) Fixed a performance issue with many objects using multiple action maps [ISXB-573] Jun 20, 2024
@AlexTyrer AlexTyrer changed the title Fixed a performance issue with many objects using multiple action maps [ISXB-573] FIX: Fixed a performance issue with many objects using multiple action maps [ISXB-573] Jun 20, 2024
Copy link
Collaborator

@lyndon-unity lyndon-unity left a comment

Choose a reason for hiding this comment

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

I've seen this fixed the performance issue and also still passes all the tests

(2 tests failed if the triggering call itself was commented out in ProcessControlStateChange :

using (InputActionRebindingExtensions.DeferBindingResolution())
)

@AlexTyrer AlexTyrer removed the request for review from ekcoh June 20, 2024 14:23
@ekcoh
Copy link
Collaborator

ekcoh commented Jun 20, 2024

@AlexTyrer Seems to be conflicts in changelog that needs to be resolved before merge.

@ekcoh ekcoh requested a review from Pauliusd01 June 20, 2024 16:01
@AlexTyrer
Copy link
Collaborator Author

@AlexTyrer Seems to be conflicts in changelog that needs to be resolved before merge.

Thanks - I've resolved this now!

@AlexTyrer AlexTyrer merged commit 4db0e76 into develop Jun 21, 2024
77 of 79 checks passed
@AlexTyrer AlexTyrer deleted the isxb-573-inputactionmap-track-need-to-resolve-bindings branch June 21, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants