-
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
base: develop
Are you sure you want to change the base?
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% 76.83% +0.02%
===========================================
Files 476 476
Lines 88726 88844 +118
===========================================
+ Hits 68155 68264 +109
- Misses 20571 20580 +9 Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
| } | ||
|
|
||
| void RegisterCustomTypes() | ||
| internal bool hasCustomTypesBeenRegistered { get; private set; } |
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.
should it be also reset after UninstallGlobals or in the init to be sure ?
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.
Overlooked the hidden instance reference to InputManager hiding inside the static API actually using a static push/popped instance. Added a reset in 858f1b7
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 agree it's safest to reset since type registration is bound to instate. The assembly type loading result is not.
| // Failed to look-up type, either type do not exist or it is a custom type. | ||
| // Check whether we have attempted to load custom types and otherwise lazily load | ||
| // types only when referenced and reattempt looking up type by name. (ISXB-1766) | ||
| if (InputSystem.s_Manager == null || InputSystem.s_Manager.hasCustomTypesBeenRegistered) |
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.
that's doesn't seems clean to add a global reference to the supposed owner of it.
It breaks the isolation.
We may add to TypeTable a generic fallback call that the owner can configure.
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 agree, I added an InputManager reference instead passed via Initialize since it's always "owned" (at least managed) by InputManager. Its strong coupling, but there is currently no point of having an indirection (with a cost).
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.
Addressed in 5cb4617
| return null; | ||
|
|
||
| InputSystem.s_Manager.RegisterCustomTypes(); | ||
| return LookupTypeRegistration(name); |
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.
maybe longer but internedName is already resolved so this should be enough
table.TryGetValue(internedName, out type);
return type;
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 switched to internedName after also reducing the scope of the recursive call in 5cb4617
…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/[email protected]/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. |
Description
Mitigates effects reported in ISXB-1766 (internal).
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:
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.