-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Porting over some optimizations #10310
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
Porting over some optimizations #10310
Conversation
| get | ||
| { | ||
| Debug.Assert(isMarkedDestroyed.HasValue, $"{GetType()} has not set a value for IsMarkedDestroyed, returning false."); | ||
| if (!isMarkedDestroyed.HasValue) |
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.
Does this need the if check if it's also being converted from Debug.Assert to Debug.AssertFormat without an interpolated string? The allocation would be happening because of the interpolated string, but the method call without it will no-op instead.
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 we just need to change anywhere we use interpolated strings in Debug.Assert calls into Debug.AssertFormat calls?
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.
Well, there's also GetType() that would still get called. Though we also changed GetType to cache it's result so it's not as expensive, but I use it as an example of Debug.AssertFormat not necessarily being a perfect solution.
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.
True! A combination of caching the type and using AssertFormat seems good though.
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.
Looked into this more...unfortunately since AssertFormat uses params object[] as a parameter, it allocs an array every call :( the if might be our only path forward @davidkline-ms
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.
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.
| switch (state) | ||
| { | ||
| case KeyboardState.Showing: | ||
| if (TouchScreenKeyboard.visible == true) |
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 think this might bust some OS versions where the .visible state isn't properly reported. That's a main reason why we wrote all this custom keyboard code in the first place. @MaxWang-MS might be able to elaborate.
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.
Thanks for pointing this out Kurtis! It is a known Unity issue that the .visible state can be inaccurate under certain circumstances, even on the latest HL2 OS. So we deliberately decided to track the state ourselves in this class instead of relying on that Unity property.
| if (pointersList[i].Pointer is T typePointer && !typePointer.IsNull()) | ||
| { | ||
| typePointers.Add(typePointer); | ||
| yield return typePointer; |
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.
We discussed this change a while back in #8118. Any chance you did any perf measurements to verify that this isn't trading garbage for perf?
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, the best solution would be to have an overload where you can pass a list in, but that would be a breaking change. The comparison in the article is not exactly valid because here you were creating a List, iterating on it with foreach and returning the IEnumerable anyway.
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
david-c-kline
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.
there are some issues in this pr that should be addressed (ex: replace assert with logerror, fix calling of AssetsContainsShaders)
| if (!AssetsContainsShaders(packageShaderFolder)) | ||
| DirectoryInfo packageShaderFolder = FindShaderFolderInPackage(); | ||
|
|
||
| if (!AssetsContainsShaders(packageShaderFolder, sentinelPath, ignoreFile)) |
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 dont see changes to AssetsContainsShaders() that reflect the new parameter list.
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.
Just pushed this change!
| get | ||
| { | ||
| Debug.Assert(isMarkedDestroyed.HasValue, $"{GetType()} has not set a value for IsMarkedDestroyed, returning false."); | ||
| if (!isMarkedDestroyed.HasValue) |
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.
Looked into this more...unfortunately since AssertFormat uses params object[] as a parameter, it allocs an array every call :( the if might be our only path forward @davidkline-ms
| get | ||
| { | ||
| Debug.Assert(isMarkedDestroyed.HasValue, $"{GetType()} has not set a value for IsMarkedDestroyed, returning false."); | ||
| if (!isMarkedDestroyed.HasValue) |
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.
| get | ||
| { | ||
| Debug.Assert(isMarkedDestroyed.HasValue, $"{GetType()} has not set a value for IsMarkedDestroyed, returning false."); | ||
| if (!isMarkedDestroyed.HasValue) |
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.
| /// <typeparam name="T">The type of pointers to request. Use IMixedRealityPointer to access all pointers.</typeparam> | ||
| /// <param name="predicate">A function that returns true when the parameter satisfies a condition.</param> | ||
| /// <returns>The first pointer in the collection that satisfies the specified condition.</returns> | ||
| T GetFirstPointerWhere<T>(System.Predicate<T> predicate) where T : class, IMixedRealityPointer; |
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 wonder if we can approach these as extension methods instead. Changing this interface would be a breaking change for anybody who has rolled their own focus provider, and I know of a handful of people who have.
| { | ||
| var spherePointers = focusProvider.GetPointers<SpherePointer>(); | ||
| foreach (var spherePointer in spherePointers) | ||
| var spherePointer = focusProvider.GetFirstPointerWhere<SpherePointer>(p => p.Controller == Pointer.Controller); |
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.
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.
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
This is semi-ported out of microsoft#10310
This is semi-ported out of microsoft#10310
This is semi-ported out of microsoft#10310
|
@keveleigh, assigning to you to continue cherry picking the key fixes |
|
@keveleigh is reviewing this PR. he will work with @jverral |
|
Closing as the key improvements have been ingested. |





Overview
Greatly reduce allocations related to focus/cursors, and MaterialInstance, which was calling renderer.sharedMaterials every frame (which allocates).
Also brings in a keyboard change from the MRTK 2.6 branch into the 2.7 branch.