-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Possible improvements of load time #76
Comments
Thanks for the issue @ShrykeWindgrace. One possible enhancement would be to optimize how the RGB colors from the theme are converted to escape sequences. When a theme is loaded, it calls an internal function (
|
One optimization I have found is to lazy-load the glyphs until they are actually used (i.e., calling I also tried folding the glyph data into the .psm1 file, but that made things objectively worse (~750ms on average), mostly spent by PowerShell loading the now-270kB .psm1 file. |
That's a good idea =)
This part of powershell I truly do not understand. We have top of line CPUs, SSDs with astronomical read speeds, 32Gb RAM, yet reading a 270Kb file takes about a second... |
IdeaI'm not really sure about the data convertion from .ps1(1 file) + .psd1(2 files) + .xml(2 files) -> hashtable -> .xml(2 files) ImplementFirst, I did $moduleRoot = $PSScriptRoot
# $glyphs = . $moduleRoot/Data/glyphs.ps1
$escape = [char]27
$colorReset = "${escape}[0m"
$defaultTheme = 'devblackops'
$userThemePath = Get-ThemeStoragePath
# Load or create default prefs
$prefs = Import-Preferences
$userThemeData,$colorSequences,$glyphs =Import-Clixml -Path "$moduleRoot/Data/Data.xml"
# Save-Preferences -Preferences $prefs
Update-FormatData -Prepend ([IO.Path]::Combine($moduleRoot, 'Terminal-Icons.format.ps1xml')) Import-Preferences.ps1: function Import-Preferences {
param(
[parameter(ValueFromPipeline)]
[string]$Path = (Join-Path (Get-ThemeStoragePath) 'prefs.xml'),
[string]$DefaultThemeName = $script:defaultTheme
)
$defaultPrefs = @{
CurrentColorTheme = $DefaultThemeName
CurrentIconTheme = $DefaultThemeName
}
if (Test-Path $Path) {
try {
Import-Clixml -Path $Path -ErrorAction Stop
} catch {
Write-Warning "Unable to parse [$Path]. Setting default preferences."
$defaultPrefs
}
} else {
Save-Preferences -Preferences $defaultPrefs # only need to save prefs if xml not exist
$defaultPrefs
}
} So there is only two read operations in most cases ResultBefore:
After:
|
@waingt That sounds like a good optimization (converting glyphs, themes, and color sequences to xml during the build process). |
@waingt That's a great improvement! On my machine Terminal-Icons load time went from 1300ms to 470ms |
Any plans to add this improvement? |
Gentle ping=) |
@waingt that is just amazing, you have saved what little sanity I have left Here are my resultsBefore: pwsh -nop -c '(Measure-Command { Import-Module Terminal-Icons }).TotalMilliseconds'
1120.7058 After: pwsh -nop -c '(Measure-Command { Import-Module Terminal-Icons }).TotalMilliseconds'
143.5407 Again great work, and thanks |
any update ? |
@ctolkien I has this issue before as well and I realized that the cause was One Drive was "clearing disk space" by keeping my modules in the cloud so they had to be downloaded to be used. Right clicking the folder and selecting "Keep available offline" helped bring it from ~4s to ~1s load times. |
@ChristopherHaws these are on OneDrive but they are still local. I notice that everytime this module is instantiated, it writes the files back to disk, which is also going to be slow. |
@ChristopherHaws so I ensured that OneDrive kept those files local and it got worse: Now nearly 4 seconds: |
@ctolkien The daemon for OneDrive could be actively monitoring what happens with the files. So, if I were you, I would try two things:
|
@ShrykeWindgrace How can I move the modules? PowerShell automatically installs them in a folder than is backed by OneDrive? Is there a variable I can change to change the module folder search path? Thanks! |
@ShrykeWindgrace / @ChristopherHaws You can modify the I tried putting this on an entirely separate drive (of exactly the same type), not managed by OneDrive or other backup providers, and it appears to be about 100ms slower, but I've had some loads which are equally as fast, so doesn't conclusively make any difference - and definitely nothing noticeable. I don't think it's OneDrive in this case. Will keep trying some of the other suggestions in this thread. |
I gave this a shot. It helped but only by about 50ms. I went from 480 to 430 on a i7-8750H. I imagine the sheer number of glyphs is the primary issue. Parsing XML is always gonna be slow. Most glyphs go unused so its probably a better idea to provide a tool that lets the user filter the glyphs by all the file types they've opened/encountered. |
I noticed a couple of things with import time of this wonderful module:
On a debian machine I get half a second (
TotalMilliseconds : 412.3335
) forImport-Module Terminal-Icons
in my$PROFILE
. Same command on a windows machine report ~1s import time.So, I've got a couple of questions:
Cheers and thanks for the good work!
Here's the output of
$trace = Trace-Script -ScriptBlock {Import-Module /nix/store/x4nsl5qaj4i38nrdy8qzkx597ha21dxx-Terminal-Icons-0.9.0/Terminal-Icons/0.9.0/Terminal-Icons.psd1 };$trace.AllLines | Format-Table
console dump
Context
I am trying to reduce the load time of a new pwsh instance.
Measure-Command {Import-Module Terminal-Icons}
proves to be one of slow points of my$PROFILE
.Your Environment
pwsh
7.2.1 on a debian (installed vianix
);pwsh-7.2.2
on a win10 (installed from MS Store)Both machines are well-off dev machines
The text was updated successfully, but these errors were encountered: