Skip to content

[Performance] ExtendedProperty JSON is parsed twice per recommendation in Az.Advisor path #28

@cocallaw

Description

@cocallaw

Summary

In the Az.Advisor code path, ExtendedProperty JSON is parsed once during the Where-Object subcategory filter, then parsed again when building the output object for each matching recommendation.

Impact

Redundant ConvertFrom-Json calls add unnecessary CPU overhead, especially noticeable with large recommendation sets across many subscriptions.

Location

  • Public/Get-AzRetirementRecommendation.ps1
    • First parse: subcategory filter scriptblock (~line 162)
    • Second parse: output object construction (~line 234)

Suggested fix

Parse ExtendedProperty once during filtering and cache the result on the object:

$subcategoryFilter = {
    if ($_.ExtendedProperty) {
        $extProps = $_.ExtendedProperty | ConvertFrom-Json
        if ($extProps.recommendationSubCategory -eq "ServiceUpgradeAndRetirement") {
            $_ | Add-Member -NotePropertyName ExtendedPropertyObject -NotePropertyValue $extProps -Force
            $true
        } else { $false }
    }
    else { $false }
}

The downstream code already checks for ExtendedPropertyObject and reuses it — this change just moves the caching into the filter so every retained item benefits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance improvementpriority: mediumMedium priority — plan for near-term

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions