Skip to content

Adapter lookup table for non-list operations on adapted resources#530

Merged
SteveL-MSFT merged 35 commits intoPowerShell:mainfrom
anmenaga:adapter_lookup_table
Sep 16, 2024
Merged

Adapter lookup table for non-list operations on adapted resources#530
SteveL-MSFT merged 35 commits intoPowerShell:mainfrom
anmenaga:adapter_lookup_table

Conversation

@anmenaga
Copy link

@anmenaga anmenaga commented Aug 24, 2024

PR Summary

This is a performance optimization that reduces time when searching for the adapter that implements a requested resource when non-list operations on this resource are invoked.

When a non-list operation on an adapted resource is invoked (e.g. dsc resource get -r Test/TestCase), discovery code first is doing List operation sequentially on all adapters until it finds which adapter implements requested resource.
If the adapter of interest happens to be in the end of line, then a huge perf cost is accumulated.
This change adds an adapter lookup table that is basically a mapping <resource type> -> <was last seen in this adapter>.
This lookup table is then used for sorting adapter list before doing List operations on them, this way the adapter of interest is searched first, reducing overall time of operation.

Adapter lookup file location:

  • on Windows: $env:LocalAppData+"dsc\AdaptedResourcesLookupTable.json"
  • on Linux and Mac: $env:HOME+".dsc/AdaptedResourcesLookupTable.json"

PR Context

Before change:

PS C:\DSCv3> # 'Test/TestCase' resource is implemented in 'Test/TestAdapter'
PS C:\DSCv3> # Search order ('List' operation) without lookup table: `Microsoft.DSC/PowerShell`, `Microsoft.Windows/WindowsPowerShell`, `Microsoft.Windows/WMI`, `Test/TestAdapter`(needed resource found here)
PS C:\DSCv3> (Measure-Command {dsc resource get -r Test/TestCase}).TotalSeconds
41.8350422

After change:

PS C:\DSCv3> # 'Test/TestCase' resource is implemented in 'Test/TestAdapter'
PS C:\DSCv3> # Search order ('List' operation) based on lookup table: `Test/TestAdapter`(needed resource found here)
PS C:\DSCv3> (Measure-Command {dsc resource get -r Test/TestCase}).TotalSeconds
2.0769161

@anmenaga anmenaga requested review from SteveL-MSFT and tgauth August 24, 2024 06:55
@anmenaga anmenaga marked this pull request as draft August 24, 2024 06:55
@anmenaga anmenaga force-pushed the adapter_lookup_table branch from aea50e2 to 2872f03 Compare August 27, 2024 20:57
@anmenaga anmenaga changed the title WIP: Adapter lookup table for non-list operations on adapted resources Adapter lookup table for non-list operations on adapted resources Aug 30, 2024
@anmenaga anmenaga marked this pull request as ready for review August 30, 2024 06:06
@SteveL-MSFT SteveL-MSFT added this pull request to the merge queue Sep 16, 2024
Merged via the queue into PowerShell:main with commit ae330c2 Sep 16, 2024
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