-
Notifications
You must be signed in to change notification settings - Fork 330
FIX: Mitigate memory allocation driven by reflective introspection of binding types ISXB-1766 #2285
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
Conversation
…tive type loading to only happen when an unresolved type is encountered in an input action asset.
PR Reviewer Guide 🔍(Review updated until commit f611a2d)Here are some key observations to aid the review process:
🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr-agent |
|
Suggestion for Suggestion: The current implementation of 🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr-agent |
Codecov ReportAll modified and coverable lines are covered by tests ✅ @@ Coverage Diff @@
## develop #2285 +/- ##
===========================================
+ Coverage 76.81% 77.45% +0.63%
===========================================
Files 476 477 +1
Lines 88726 91957 +3231
===========================================
+ Hits 68155 71224 +3069
- Misses 20571 20733 +162 Flags with carried forward coverage won't be shown. Click here to find out more.
... and 65 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Packages/com.unity.inputsystem/InputSystem/Utilities/TypeTable.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Utilities/TypeTable.cs
Outdated
Show resolved
Hide resolved
…Removed property that could be internal to InputManager and be returned as method result instead.
…ts between InputManager instances.
|
Persistent review updated to latest commit 7c2cac7 |
|
Persistent review updated to latest commit dd3c867 |
|
Persistent review updated to latest commit 5f2fe5c |
|
Persistent review updated to latest commit f611a2d |
|
jfreire-unity
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm approving this so it doesn't get blocked. I think it's the best approach to solve the issue in a short time. It's still unclear what the best solution will be going forward, so perhaps we should track that work after this lands.
My only question is about the steps to validate this. How can I validate (and QA as well) that this change doesn't allocate the +19MB of memory? Would there be a way to automate this and add a test for it?
Yes, it's documented in the manual. It was easier to decipher before Processor page was edited in recent versions IMO, but it is at least in API docs linked from "Remarks" here: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.16/api/UnityEngine.InputSystem.InputSystem.html |
bmalrat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good to me to mitigate the issue
IMO, the potential solution I can see which requires a bit of exploration would be to:
See internal JIRA for more details. |
You may be able to check it within the profiler marker InputManager.RegisterCustomTypes which should not be called. |
|
Not seeing any functionality issues yet but I'm having trouble profiling it. Hoping to finish by tomorrow morning |
|
This change seems to be fine for XR packages. We generally use |
| - Deferred auto-registration of processors, interactions and composite binding types referenced by `InputActionAsset` | ||
| to only happen once when an unresolved type reference is found in an action definition. This avoids reflective | ||
| type loading from assemblies for all cases where the Input System is not extended. (ISXB-1766). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - Deferred auto-registration of processors, interactions and composite binding types referenced by `InputActionAsset` | |
| to only happen once when an unresolved type reference is found in an action definition. This avoids reflective | |
| type loading from assemblies for all cases where the Input System is not extended. (ISXB-1766). | |
| - Deferred auto-registration of processors, interactions and composite binding types referenced by `InputActionAsset` to only happen once when an unresolved type reference is found in an action definition. This avoids reflective type loading from assemblies for all cases where the Input System is not extended. (ISXB-1766). |
I don't think you should manually word wrap.
I also got this impression looking at the code but it doesn't help if you rely on PWIA, a potential solution for that is being looked at in parallel which might require some orchestration on both sides. But happy to hear you have kept your manual registration code. Lets keep that until there is clarity on how to properly handle this without reflective runtime operations long term. |
Pauliusd01
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly couldn't tell much of a difference when profiling different scenes, I didn't see any reflection code showing up with or without custom processors but the functionality seemed unaffected so it should be fine 🤞 Release testing will hopefully reveal anything missed
Description
Mitigates effects reported in ISXB-1766 (internal). This is not a fix but a mitigation (reducing number of scenarios when Reflection is used). A parallel track is being investigated in #2288 relying on Roslyn source generators and some changes to type registration and management to avoid Reflection instead. This parallel track is less of a quick fix.
The goal is to reduce memory allocations from reflective type loading to only happen when an unresolved type is encountered in an input action asset. The drawback of this is that GC pressure may be postponed from outside intialization. The benefit is that no reflective type loading occurs if no custom type extensions are referenced from
.inputactionassets, which would previously unconditionally load an introspect all assemblies unconditionally.Some scenarios:
A proper fix is also investigated in #2288 (pending), with higher risk and halo effect.
Testing status & QA
Only quickly verified with a custom processor type in a local project so far.
Overall Product Risks
May have halo effects, e.g. on XRI.
Comments to reviewers
This doesn't solve the reported behavior, only reduces to number of occasions when it happens.
Checklist
Before review:
Changed,Fixed,Addedsections.Area_CanDoX,Area_CanDoX_EvenIfYIsTheCase,Area_WhenIDoX_AndYHappens_ThisIsTheResult.During merge:
NEW: ___.FIX: ___.DOCS: ___.CHANGE: ___.RELEASE: 1.1.0-preview.3.