Skip to content

Conversation

SteveL-MSFT
Copy link
Member

PR Summary

When using adapted resources, the engine will dynamically generate a nested configuration. Each configuration (outer and inner) would incur the cost of performing discovery. This change makes command discovery retain an in-memory static cache so that any multiple discoveries will just use the previous one.

Copy link
Contributor

@Copilot 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 implements static memory caching for command discovery to avoid redundant discovery operations when using adapted resources. The engine previously performed discovery multiple times for nested configurations, which was inefficient.

Key changes:

  • Adds a static cache module using global statics with mutexes for thread-safe access
  • Refactors CommandDiscovery to use the cache instead of instance fields
  • Replaces direct field access with cache getter/setter functions

Reviewed Changes

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

File Description
dsc_lib/src/discovery/mod.rs Adds the new cache module to the discovery module
dsc_lib/src/discovery/command_discovery_cache.rs Implements the static cache with thread-safe global storage for discovered resources
dsc_lib/src/discovery/command_discovery.rs Refactors CommandDiscovery to use the static cache instead of instance fields

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Member

@andyleejordan andyleejordan left a comment

Choose a reason for hiding this comment

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

Some questions, and some Rust I need to go look up.

Copy link
Member

@andyleejordan andyleejordan left a comment

Choose a reason for hiding this comment

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

Oh I forgot to approve this.

Steve Lee (POWERSHELL HE/HIM) (from Dev Box) and others added 7 commits October 2, 2025 12:14
@SteveL-MSFT
Copy link
Member Author

@andyleejordan FYI - the mutex with macros was resulting in a deadlock, changing to using RwLock which is better anyways since don't need to mutate every time fixes this

@andyleejordan
Copy link
Member

andyleejordan commented Oct 2, 2025

@andyleejordan FYI - the mutex with macros was resulting in a deadlock, changing to using RwLock which is better anyways since don't need to mutate every time fixes this

I'm curious where exactly the deadlock was. If it didn't deadlock in the same way with the wrappers, that indicates we're acquiring the lock in the same scope in some place where we meant not to hold the lock (and so were implicitly depending on the lock expiring inside the wrapper)...ah, probably where we're reading to check is_empty() or clone() it and then writing to it with extend()...so was it here?

fn discover()
...
        match kind {
            DiscoveryKind::Resource => {
...
// clone and then extend deadlocking?

If that's the case, then I agree, RwLock is the correct type to use given the usage.

@SteveL-MSFT SteveL-MSFT added this pull request to the merge queue Oct 3, 2025
Merged via the queue into PowerShell:main with commit 784daea Oct 3, 2025
4 checks passed
@SteveL-MSFT SteveL-MSFT deleted the discovery-static branch October 3, 2025 00:37
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