OutTabulatorView
OutTabulatorView copied to clipboard
Default Behavior to get all properties has performance issues
I just installed and tried a very simple test case
Get-Process | otv
I thought something was wrong until 20+ seconds later a browser window popped up and even then took a bit for it to render.
I did some quick measurement tests of Get-Process, then outputting to Out-GridView, then to Out-TabularView and here are the results (edited for seconds only):
C:\Users\derek.price> Measure-Command { get-process }
TotalSeconds : 0.0116812
C:\Users\derek.price> Measure-Command { get-process | ogv }
TotalSeconds : 0.3069469
C:\Users\derek.price> Measure-Command { get-process | otv }
TotalSeconds : 19.7969857
It seems that Get-Process dumps a very small subset of the entire property set while Out-TabularView expands everything which is why it took so long. I'm not sure what to suggest here other than it was very unexpected.
Other than that the module is great - kudos and thanks!
Yeah, I grab all the properties from the incoming object. That's why it takes longer. Next, I'll add getting the defaults so this should be faster.
Found out about this module from a thread on Reddit, and noticed a possible cause of this issue looking at the code.
I'm willing to bet the problem here is that you're calling ConvertTo-Json -Depth 5
on line 31 and line 65. There's a really good reason that the default value of this command is 2.
Try this:
$x = Get-Item . | ConvertTo-Json -Depth 5 -Compress
That gets the current directory and converts its properties to depth 5. On my system, that takes well over 10 seconds, and $x
ends up over 43 million characters long. Yes, it generates over 40 megs of data from a single instance of a single object because it gets into function prototypes and type definitions. Even the default depth of 2 is a bit excessive here if you try it, though it only creates about 25 KB of data for me.
If you want to make depths larger than 2 possible, I'd create a parameter that allows the user to configure it and pass that to ConvertTo-Json
.
Good call @AikenBM ! Up for doing a PR?