Skip to content

[Performance] Export-AzRetirementReport accumulates and copies arrays inefficiently #29

@cocallaw

Description

@cocallaw

Summary

Export-AzRetirementReport uses $allRecs += $Recommendations (array concatenation) in its process block, which creates a new array on every pipeline input. It then creates additional full copies for transformation and CSV sanitization.

Impact

For large recommendation sets, this causes O(n²) memory allocation from += and multiple full-set copies during export.

Location

  • Public/Export-AzRetirementReport.ps1
    • += accumulation: line 39
    • Transformation copy: lines 53–81
    • CSV sanitization copy: lines 86–107

Suggested fix

Use [System.Collections.Generic.List[object]] instead of +=:

begin {
    $allRecs = [System.Collections.Generic.List[object]]::new()
}

process {
    foreach ($rec in $Recommendations) {
        $allRecs.Add($rec)
    }
}

For the transform and sanitize steps, consider processing items inline per format rather than creating separate full copies of the dataset.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions