New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import-module is very slow, take from 7-16 seconds #35
Comments
I added some timings to the Carbon.psm1 file and it turns out the entire import time is taken up by checking if the Win32_OptionalFeature is installed, about 19 seconds in this attempt. Dot-sourcing all the function files only takes a second.
|
Hey again,
as you can see the dot-sourcing is the slowdown here. |
And here for the complete log with timestamps on the dot sourcing:
|
Hey Aaron, |
@splatteredbits could you please open this again? :) |
Why? How long is it taking you to import? |
well the latest test show 12 seconds My PC is running with "Windows Defender Advanced Threat Protection Service".
okey so I found this: https://www.codykonior.com/2019/04/18/expensive-dot-sourcing-in-powershell-modules-revisited/ and tried that out: <#
Write-Timing ('Dot-sourcing functions.')
Get-ChildItem -Path $functionRoot -Filter '*.ps1' |
Where-Object { -not $doNotImport.Contains($_.Name) } |
ForEach-Object {
Write-Verbose ("Importing function {0}." -f $_.FullName)
. $_.FullName | Out-Null
}
#>
Write-Timing ('Test new Way Dot-sourcing functions.')
$content = Get-ChildItem -Path $functionRoot -Filter '*.ps1' | ForEach-Object {
[System.IO.File]::ReadAllText($_.FullName, [Text.Encoding]::UTF8) + [Environment]::NewLine
}
. ([scriptblock]::Create($content)) that did a very drastic drop in load time:
|
Yowzers. That's amazing that it takes 12 seconds to read and parse 200 files. Can you merge them all into one external file, like I'm thinking I'll merge all the files into one |
you can get that here:
|
OK. I think I've finally fixed it (or made it as fast as I can). Please download Carbon.zip, unblock it, unzip it, and let me know how long it takes you to import Carbon in a fresh console. On my machine, it takes about two seconds now. These changes will be in Carbon 2.9. |
yes much better!
|
Fixed in Carbon 2.9.0-rc587, now available on the PowerShell Gallery and GitHub. Please takea few minutes to download and test that your issue is fixed. We'll be publishing the final version of 2.9.0 Wednesday or Thursday. |
it's still quick:
|
Maybe include a test for module loading requires load time under 1 sec? :D |
That's a tricky test. When developing, Carbon isn't optimized, meaning there are over 200 files that get dot-sourced every import, which take anywhere from 7 to 15 seconds. Carbon builds take about 20 minutes. I'd hate to have a build fail because one time Carbon imported really slow just that one time. 🤔 |
I am very happy to see it imported in less than a second for you. |
OK. So, I've written a test that imports Carbon seven times, throws out the fastest and the slowest speeds, than averages the remaining five and asserts that the average import takes less than a second. I think that approach should help smooth out any weird imports that take longer/faster than usual. |
2.9.0 is out. |
Resolutions:
The text was updated successfully, but these errors were encountered: