Skip to content

CacheView optimizations - #68953

Merged
dariatiurina merged 1 commit into
dotnet:mainfrom
dariatiurina:cache-dictionary
Sep 2, 2026
Merged

dariatiurina merged 1 commit into
dotnet:mainfrom
dariatiurina:cache-dictionary

Conversation

@dariatiurina

Copy link
Copy Markdown
Contributor

CacheView optimizations

Description

In CacheView component we use static dictionary that caches results of the sorting of parameters which we use in VaryBy parameter optimization. We do not need it and it bring unnecessary complexity for the calculation of CacheKey, because one VaryBy parameter usually have 1 to 3 values and sorting those doesn't require caching.

@dariatiurina dariatiurina self-assigned this Sep 1, 2026
@dariatiurina
dariatiurina requested a lite review from Copilot September 1, 2026 12:53
@dariatiurina
dariatiurina marked this pull request as ready for review September 1, 2026 12:58
@dariatiurina
dariatiurina requested a review from a team as a code owner September 1, 2026 12:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR simplifies CacheView cache-key computation by removing the static sorted-name cache used to canonicalize comma-separated VaryBy* parameter name lists, and instead re-splitting/re-sorting names per call.

Changes:

  • Removed the ConcurrentDictionary-based cache (and Hot Reload invalidation hook) used for caching sorted vary-by name lists.
  • Updated CollectSortedNames to build and sort the list on demand and return a List<string> for enumeration.
File summaries
File Description
src/Components/Endpoints/src/CacheView/CacheViewKeyResolver.cs Removes the static cache for sorted vary-by names and replaces it with per-call parsing/sorting in key computation.
Review details

Suppressed comments (1)

src/Components/Endpoints/src/CacheView/CacheViewKeyResolver.cs:163

  • CollectSortedNames currently calls AsSpan() repeatedly and creates an un-sized List, which can add avoidable overhead now that this runs per ComputeKey invocation. Capturing the span once and pre-sizing the list (typical VaryBy* counts are small) keeps the simplified approach while reducing per-call overhead.
        var names = new List<string>();
        foreach (var segment in separatedValues.AsSpan().Split(','))
        {
            var name = separatedValues.AsSpan()[segment].Trim();
            if (!name.IsEmpty)
            {
                names.Add(name.ToString());
            }
        }
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@javiercn javiercn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, are there tests for this already and didn't change?

@dariatiurina

Copy link
Copy Markdown
Contributor Author

@javiercn I didn't test caching, as it was only improvement, so none of the tests needed deletion or updating.

@Youssef1313 Youssef1313 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this target release/11.0 instead?

@dariatiurina

Copy link
Copy Markdown
Contributor Author

@Youssef1313 I will backport it after it merged to main

@dariatiurina

Copy link
Copy Markdown
Contributor Author

/ba-g Build insights is hanging

@Youssef1313

Copy link
Copy Markdown
Member

@Youssef1313 I will backport it after it merged to main

That's fine. It's also possible to only merge it to release/11.0. There is an automation that will get it later to main.

@dariatiurina
dariatiurina merged commit 6fd0a4c into dotnet:main Sep 2, 2026
33 checks passed
@dariatiurina

Copy link
Copy Markdown
Contributor Author

/backport to release/11.0

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@github-actions github-actions Bot mentioned this pull request Sep 2, 2026
5 of 11 tasks
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 3, 2026
wtgodbe pushed a commit that referenced this pull request Sep 3, 2026
Co-authored-by: Daria Tiurina <[email protected]>
@dariatiurina
dariatiurina deleted the cache-dictionary branch September 29, 2026 09:44
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.

4 participants