Skip to content
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

Conversation

SimonDarksideJ
Copy link
Contributor

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

This optional section is a place where you can detail the specific type of verification
you want from reviewers. For example, if you want reviewers to checkout the PR locally
and validate the functionality of specific scenarios, provide instructions
on the specific scenarios and what you want verified.

If there are specific areas of concern or question feel free to highlight them here so
that reviewers can watch out for those issues.

As a reviewer, it is possible to check out this change locally by using the following
commands (substituting {PR_ID} with the ID of this pull request):

git fetch origin pull/{PR_ID}/head:name_of_local_branch

git checkout name_of_local_branch

Co-authored-by: microsoft-github-policy-service[bot] <77245923+microsoft-github-policy-service[bot]@users.noreply.github.com>
@SimonDarksideJ SimonDarksideJ changed the title Update caches systems references to be actual caches and not an additional 0n lookup Update caches systems references to be actual caches and not an additional 0(n) lookup May 21, 2022
@keveleigh
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

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;
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

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!

@keveleigh
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@keveleigh keveleigh changed the base branch from main to releases/2.8.1 June 14, 2022 17:10
@keveleigh keveleigh merged commit 2b471d9 into microsoft:releases/2.8.1 Jun 14, 2022
@keveleigh
Copy link
Contributor

Thanks for this change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants