Improve performance of Get-GitHubContent #232
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The call to
ConvertTo-SmarterObject
was adding a significant amount of time to the execution of Get-GitHubContent.The reasoning behind this was that the return of
Invoke-WebRequest
for this repo'sREADME.md
was an array of [int32] that contained 22,000+ entries (one byte per entry). Because the array was created byConverFrom-Json
, each[int32]
was also an[object]
, which meant that it was considered a[PSCustomObject]
inside ofConverTo-SmarterObject
, which caused it to do a lot of unnecessary work. Piping in 22,000 objects and doing all of that unnecessary work to end up just callingWrite-Output
on the original value took a lot of time.The fix here was to skip trying to convert the result to a smarter object if it wasn't going to be a convertible object in the first place.
I also added in protection directly to
ConverTo-SmarterObject
as well. It made things better than the current runtime, but still twice as slow as not calling it in the first place (average runtime of above command was 3.5 seconds when we allowed it to go into the command and then do nothing).This doesn't end up saving much time with the execution of
Tests/GitHubContents.tests.ps1
because the file being returned is so small, but this should have some nice user experience improvements in practical usage.Issues Fixed
None
References
n/a
Checklist
Comment-based help added/updated, including examples.Changes to the manifest file follow the manifest guidance.Relevant usage examples have been added/updated in USAGE.md.If desired, ensure your name is added to our Contributors list