Unity-Technologies / InputSystem

An efficient and versatile input system for Unity.
Other
1.42k stars 306 forks source link

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

Closed AlexTyrer closed 2 months ago

AlexTyrer commented 2 months ago

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:

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:

During merge:

After merge:

ekcoh commented 2 months ago

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

AlexTyrer commented 2 months ago

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

Thanks - I've resolved this now!