iainbrighton / PScribo

PowerShell documentation framework
MIT License
232 stars 35 forks source link

PScribo takes a long time to load #10

Closed llstrk closed 8 years ago

llstrk commented 8 years ago

It takes around 5-6 seconds to load PScribo in a normal PowerShell session. When using Visual Studio Code, it takes around 10 seconds. And because of the way VS Code works, it needs to load all modules for every run, which makes it virtually impossible to use VS Code with PScribo. The time is spend in PScribo.psm1 at line 6, where it loads all .ps1 files. It takes around 300-400ms to load each .ps1 file, which is presumably because it needs to validate the signature on each file.

Moving all code into a single .ps1 file reduces the load time to <1sec.

I agree that for structure and overview, it's best to split all functions into separate files for development. But it could be a build task to simply compile a single big .ps1 file, and then sign that. Here's a simple example of how I've tested it. I then simply remove all .ps1 files from Functions and Plugins and copy the new file in.

$pscriboRoot = 'C:\Program Files\WindowsPowerShell\Modules\PScribo\0.7.8.17'
$ps1Files = Get-ChildItem -Path "$pscriboRoot\Functions","$pscriboRoot\Plugins" -Exclude '*.Tests.ps1'
$funcFile = 'C:\temp\pscribefunctions.ps1'
"# Build for test" | Out-File -FilePath $funcFile
foreach ($file in $ps1Files) {
    $content = Get-Content -Path $file.FullName
    foreach ($line in $content) {
        $checkLine = $line
        if ($checkLine -notlike '#*') {
            $checkLine.Trim() | Out-File -FilePath $funcFile -Append
        }
    }
}
iainbrighton commented 8 years ago

Hmmm. I've not seen that long load time (and I use VS Code too). There are indeed differences between loading the signed version:

[14] C:\..\Dropbox\PowerShell\> Measure-Command { ipmo .\Modules\PScribo\Build\PScribo\PScribo.psd1 -Force }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 195
Ticks             : 1953790
TotalDays         : 2.26133101851852E-06
TotalHours        : 5.42719444444444E-05
TotalMinutes      : 0.00325631666666667
TotalSeconds      : 0.195379
TotalMilliseconds : 195.379

and the unsigned/source version:

[15] C:\..\Dropbox\PowerShell\> Measure-Command { ipmo .\Modules\PScribo\PScribo.psd1 -Force }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 87
Ticks             : 873790
TotalDays         : 1.01133101851852E-06
TotalHours        : 2.42719444444444E-05
TotalMinutes      : 0.00145631666666667
TotalSeconds      : 0.087379
TotalMilliseconds : 87.379

@llstrk However, this is nowhere near the load time that you're seeing. How are you using PScribo within VS Code?

PScribo Bundle

It is possible to create a single "bundled" file if you have PSake installed. The thinking here, is that this will be published to the PowerShell Gallery as a script in future as well (should you wish/need to consume it in that manner):

[41] C:\....\Modules\PScribo [dev +0 ~2 -0]\> Invoke-psake -buildFile .\Build.PSake.ps1 -taskList Clean,Setup,Deploy,Bundle
psake version 4.5.0
Copyright (c) 2010-2014 James Kovacs & Contributors

Executing Clean
 Removing build base directory "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build".
Executing Setup
 Building module "PScribo".
 Using version number "0.7.9.22".
 Creating build directory "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo".
Executing Deploy
 Copying release files to build directory "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo".
Executing Bundle
 Creating bundle file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Release\PScribo-v0.7.9.22-Bundle.ps1".
  Creating bundle header.
  Creating bundle license.
  Creating bundle resources.
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\BlankLine.ps1".
  Bundling internal file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\BlankLine.Internal.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\Conversion.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\Document.ps1".
  Bundling internal file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\Document.Internal.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\Export-Document.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\GlobalOption.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\LineBreak.ps1".
  Bundling internal file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\LineBreak.Internal.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\Logging.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\PageBreak.ps1".
  Bundling internal file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\PageBreak.Internal.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\Paragraph.ps1".
  Bundling internal file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\Paragraph.Internal.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\Section.ps1".
  Bundling internal file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\Section.Internal.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\Style.ps1".
  Bundling internal file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\Style.Internal.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\Table.ps1".
  Bundling internal file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\Table.Internal.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\TableStyle.ps1".
  Bundling internal file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\TableStyle.Internal.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\TOC.ps1".
  Bundling internal file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Functions\TOC.Internal.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Plugins\OutHtml.ps1".
  Bundling internal file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Plugins\OutHtml.Internal.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Plugins\OutText.ps1".
  Bundling internal file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Plugins\OutText.Internal.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Plugins\OutWord.ps1".
  Bundling internal file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Plugins\OutWord.Internal.ps1".
  Bundling file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Plugins\OutXml.ps1".
  Bundling internal file "C:\Users\iainb\Dropbox\PowerShell\Modules\PScribo\Build\PScribo\Plugins\OutXml.Internal.ps1".
  Creating bundle footer.

Build Succeeded!

----------------------------------------------------------------------
Build Time Report
----------------------------------------------------------------------
Name   Duration
----   --------
Clean  00:00:00.0331984
Setup  00:00:00.0764970
Deploy 00:00:00.3189822
Bundle 00:00:00.2721479
Total: 00:00:00.7155423
llstrk commented 8 years ago

I just tested on a different machine, and it shows results that matches yours (44ms load time). I'm stuck with a Win7 with WMF5 where I originally tested it, and perhaps there is some issue there. I'll assume that it's a problem at my end and it's not worth looking into.

Thanks!