Skip to content

Conversation

@keegan-caruso
Copy link
Contributor

Based on #3239

Do not add items if cache is full or compacting.
Under heavy load, stress tests showed that the LRUCache was unable to keep up a change was made to avoid adding to the cache if we detect it was full or compacting.

A change to start TaskEventQ on startup instead of starting and stopping improves performance and simplifies the code.
We were not checking is a SignatureProvider was actually added to the cache. This is important as if the SignatureProvider is not added, the cache will not be able to properly apply the dispose logic and kernel objects could pile up.

Do not add items if cache is full or compacting.
- Remove TaskCount, this is internal, but is not used outside of the assembly so can be removed
- Also remove task count from InMemoryCryptoProviderCache
- Make fields readonly as appropriate
- Fix a few comments
- Remove tests that are no longer relavent
@pmaytak
Copy link
Contributor

pmaytak commented Dec 2, 2025

@copilot Generate summary of the changes and separate the source and test changes.

Copy link
Contributor

Copilot AI commented Dec 2, 2025

@pmaytak I've opened a new pull request, #3375, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot finished reviewing on behalf of pmaytak December 2, 2025 17:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces memory consumption in the EventBasedLRUCache by preventing items from being added when the cache is full or compacting. Under heavy load, the cache was unable to keep up, so a change was made to reject new items when the cache is at or above 95% capacity.

Key changes include:

  • Converting SetValue to TrySetValue throughout the codebase to allow callers to detect when items are not added
  • Simplifying the task lifecycle by starting the event queue task at construction and running it for the lifetime of the cache
  • Ensuring SignatureProviders are actually added to the cache before associating them with the cache instance

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
EventBasedLRUCache.cs Main implementation changes: added early return when compacting, simplified task lifecycle from start/stop to long-running, added TrySetValue methods, improved consistency in map/linked list operations
InMemoryCryptoProviderCache.cs Fixed spelling errors (Trys → Tries), added check to ensure TrySetValue succeeds before associating provider with cache, updated Dispose to use StopEventQueueTaskImmediately
EventBasedLRUCacheTests.cs Updated all SetValue calls to TrySetValue, added tests for new behavior where items are not added when cache is full, added Collection attribute for test isolation
CryptoProviderFactoryTests.cs Removed obsolete tests related to task lifecycle management that are no longer applicable with the new long-running task design
BaseConfigurationManager.cs Updated to use TrySetValue instead of SetValue for consistency
InternalAPI.Shipped.txt Removed TaskCount property that is no longer needed
InternalAPI.Unshipped.txt Added new TrySetValue methods and StopEventQueueTaskImmediately to public API surface

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