Skip to content

Commit

Permalink
feat: Further improved runtime of utilities (#618)
Browse files Browse the repository at this point in the history
## Description

1. Improved runtime of Set-ModuleReadMe utility by building all test
files per modules using a thread each.
   
   Impact:
   
> Runtime of test runs ***before*** change on module 'Cognitive
Services'
   > 1. 20 s
   > 2. 17 s
   > 3. 18 s
   > 4. 17 s
   > 5. 17 s
   > </br>
   >
> Runtime of test runs ***after*** change on module 'Cognitive Services'
   > 1. 11 s
   > 2. 9 s
   > 3. 9 s
   > 4. 10 s
   > 5. 10 s


| Pipeline |
| - |
|
[![avm.res.key-vault.vault](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml/badge.svg?branch=users%2Falsehr%2FreadMeSpeadup&event=workflow_dispatch)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml)
|

---------

Co-authored-by: Erika Gressi <[email protected]>
  • Loading branch information
AlexanderSehr and eriqua authored Nov 27, 2023
1 parent 88080e7 commit 83fde1a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion avm/utilities/pipelines/sharedScripts/Set-ModuleReadMe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1182,14 +1182,27 @@ function Set-UsageExamplesSection {
############################
## Process test files ##
############################

# Prepare data (using thread-safe multithreading) to consume later
$buildTestFileMap = [System.Collections.Concurrent.ConcurrentDictionary[string, object]]::new()
$testFilePaths | ForEach-Object -Parallel {
$folderName = Split-Path (Split-Path -Path $_) -Leaf
$buildTemplate = bicep build $_ --stdout | ConvertFrom-Json -AsHashtable

$dict = $using:buildTestFileMap
$null = $dict.TryAdd($folderName, $buildTemplate)
}

# Process data
$pathIndex = 1
$usageExampleSectionHeaders = @()
$testFilesContent = @()
foreach ($testFilePath in $testFilePaths) {

# Read content
$rawContentArray = Get-Content -Path $testFilePath
$compiledTestFileContent = bicep build $testFilePath --stdout | ConvertFrom-Json -AsHashtable
$folderName = Split-Path (Split-Path -Path $testFilePath) -Leaf
$compiledTestFileContent = $buildTestFileMap[$folderName]
$rawContent = Get-Content -Path $testFilePath -Encoding 'utf8' | Out-String

# Format example header
Expand Down

0 comments on commit 83fde1a

Please sign in to comment.