-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Update caches systems references to be actual caches and not an additional 0(n) lookup #10606
Update caches systems references to be actual caches and not an additional 0(n) lookup #10606
Conversation
Co-authored-by: microsoft-github-policy-service[bot] <77245923+microsoft-github-policy-service[bot]@users.noreply.github.com>
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
@@ -20,59 +20,77 @@ namespace Microsoft.MixedReality.Toolkit | |||
/// </summary> | |||
public static class CoreServices | |||
{ | |||
private static IMixedRealityBoundarySystem boundarySystem; |
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 investigated this approach a while back (CC @MaxWang-MS) and decided against it, but I don't remember the exact reason now...
If we go this approach now, we'll probably want to clear these new caches in ResetCacheReference
and ResetCacheReferences
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'll look to update it and clear the caches from that call. Although I am concerned why you would even need to reset the caches as all the systems listed in this function are transient, meaning they should never be cleared for the lifetime of the runtime.
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.
Updated as per your request @keveleigh
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.
all the systems listed in this function are transient, meaning they should never be cleared for the lifetime of the runtime.
Just to make sure we're talking about the same thing, my understanding of "transient" and "should never be cleared for the lifetime of the runtime" are two different things: the first is short-lived, and the other sounds more long-lived.
Either way though, we don't assert that MRTK services are specifically one or the other! Devs may swap profiles at runtime, leading to these cached references potentially going stale. The cache clearing logic all happens in MixedRealityToolkit.cs when the profile is changed and the services are torn down and spun back up.
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 also going to investigate cherry-picking this to 2.8.1. I think this will help with a selection of perf issues I've been strategically targeting. Thanks!
…e references, as per request
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Thanks for this change! |
Overview
The Service registry is effectively a 0n lookup system using a dictionary, the dictionary is used primarily to ensure fast 0n lookup and also provide unique adherence to the single service principle of dependency injection.
This change resolves an issue whereby the current "CoreServices" systems lookups are actually not caching / improving lookup performance by adding an additional 0n lookup on top of / in replacement of the original 0n lookup.
Simply put, this provides direct references to the the instantiated services in the service registry rather than looking them up, potentially every update frame.
I have left in the updated cache table, although it is likely redundant.
Changes
Simply adds direct reference caches for each of the core systems identified in the "Core Systems" cache.
Verification