You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Performance of Windows PowerShell is better then PowerShell Core #7112
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.WG-Cmdletsgeneral cmdlet issuesWG-Engine-Performancecore PowerShell engine, interpreter, and runtime performance
I get very strange and disturbing performance results for Import-Csv cmdlet.
Import 111 Mb csv log file:
On Windows PowerShell always ~ 3.7 sec. Memory ~ 10 Mb.
-On PowerShell Core from 6 sec up to 27 sec - each subsequent launch increases the time by 1-2-3 seconds. Memory grow from 1 Mb to 105 Mb. After waiting some minutes memory decreases to ~1 MB and agaim the cmdlet take ~6 sec.
Ilya (@iSazonov) we have seen similar memory growth with string related activities in JSON too. I suspect .NET Core is just greedier with its GC than Framework.
Ilya (@iSazonov) Your description sounds like it might be a case of the garbage collector falling behind. Do you have a repro I can run? It's probably worth measuring any difference between GCSettings.IsServerGC true and false.
FWIW, GCSettings.IsServerGC seems to be false by default for both powershell.exe and pwsh.exe. As I understand it, that default means that there is one GC thread regardless of how many threads are simultaneously producing garbage. If I'm understanding this right, any managed code invoked by PowerShell that is both CPU-bound and well-parallelized is likely to run out of memory if you have enough cores and it runs long enough.
It could be that whatever Import-Csv (and the JSON activities Mark Kraus (@markekraus) reported) are doing became more parallelized from Windows PowerShell to PowerShell Core.
It could be that whatever Import-Csv (and the JSON activities Mark Kraus (@markekraus) reported) are doing became more parallelized from Windows PowerShell to PowerShell Core.
Then my test had to be even faster than in Windows PowerShell but it is 3-10(!) times slower from the first run.
Although speed and memory can be different problems.
Yes, but Windows PowerShell frees the memory so quickly that sometimes memory consumption can not be seen.
I also see that in your test PowerShell Core is much slower.
I did a bit of iterative testing with a smaller CSV file (104866 bytes). On my system, the results show that Import-Csv performance does vary between back-to-back runs. The minimum runtime was 71 ms and the maximum was 192 ms. It looks like the runtime would decrease each time the GC came along. I'm running PowerShell inside a Docker container (mcr.microsoft.com/powershell:centos-7).
I understand this issue was filed based on processing much larger input files (>100 MB), so I hope these findings are not a distraction; I thought the findings may still be relevant.
Ryan Hardin (@rthardin) Thanks for great tests! Could you please continue and test on Windows - for PowerShell Core and Windows PowerShell for comparison?
I started with Import-Csv and temporary disable output in the C# code. Results was well. So I guess that root of problems in creating PSObject and next two tests confirm this. Windows PowerShell is 30-100 percent faster.
It's unclear where the problem is - in PowerShell Core or in .Net Core.
Ilya (@iSazonov) to see if we slowed down creating PSObjects (looking at the Import-CSV cmdlet, it's really just adding NoteProperty members to a PSObject), I ran this test:
If you have symbols to system.management.Automation, setting up you symbol path (File -> Set Symbol Path) and source path (File -> Set Source Path), and then you can right click on a node name and select Goto Source, and PerfView will take you to the line (attributed with metric). This allows you to see exactly what line is involved.
Note that inlining can often make it hard to follow because the name in the source is really the caller (or caller's caller …). Having the line number (which by the way is approximate, it may be the line before as well), is helpful to disambiguate.
If you ever get suspicious about things, you can fall back to the debugger. Set breakpoints (probably with hit counts, every 1000 or so) for some of the locations that PerfView pointed you at and you can see if they agree with the debugger.
I have looked at lots of traces, and I have only rarely seen something where a name could not be explained by inlining only very, very rarely (and it could have been me misinterpreting the code). If by checking with the debugger, you believe you have found such a case, I would need all the source, PDBs and repro information to really investigate the issue.
Vance Morrison (@vancem) We haven't published PDB files for RC1. In PerfView log I saw that it search crossgen.exe and coped the utility in startup directory - right? After that I can see entry points in system.management.Automation
Dongbo Wang (@daxian-dbw) After Staffan Gustafsson (@powercode) improvements for PSObject all cmdlets works faster with the objects and make less allocations.
After moving to .Net Core 3.0 we get better GC. Now GC does cleanups even better .Net Framework (I say about the tests I did here). Perhaps .Net Core 3.0 add a performance too but I don't compare with previous PowerShell Core released versions.
What do you mean by one column and 700 columns?
In my tests I generate csv files. In first test the csv file consists of one column. Second - 700 columns. The first test shows a general increase in performance (I would assume that most of it comes from .Net Core 3.0). Second one explicitly shows an increase in performance which comes from Staffan Gustafsson (@powercode) PR.
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.WG-Cmdletsgeneral cmdlet issuesWG-Engine-Performancecore PowerShell engine, interpreter, and runtime performance
Activity
markekraus commentedon Jun 19, 2018
Ilya (@iSazonov) we have seen similar memory growth with string related activities in JSON too. I suspect .NET Core is just greedier with its GC than Framework.
But the slow down.. that is concerning.
iSazonov commentedon Jun 19, 2018
Dongbo Wang (@daxian-dbw) If you are working on performance tests this may be of interest to you.
iSazonov commentedon Jun 20, 2018
Maybe related #6965 (memory).
/cc alx9r
alx9r commentedon Jun 20, 2018
Ilya (@iSazonov) Your description sounds like it might be a case of the garbage collector falling behind. Do you have a repro I can run? It's probably worth measuring any difference between
GCSettings.IsServerGCtrue and false.FWIW,
GCSettings.IsServerGCseems to be false by default for both powershell.exe and pwsh.exe. As I understand it, that default means that there is one GC thread regardless of how many threads are simultaneously producing garbage. If I'm understanding this right, any managed code invoked by PowerShell that is both CPU-bound and well-parallelized is likely to run out of memory if you have enough cores and it runs long enough.It could be that whatever Import-Csv (and the JSON activities Mark Kraus (@markekraus) reported) are doing became more parallelized from Windows PowerShell to PowerShell Core.
iSazonov commentedon Jun 20, 2018
alx9r The repo is simple
The file I used has ~110 Mb size.
Then my test had to be even faster than in Windows PowerShell but it is 3-10(!) times slower from the first run.
Although speed and memory can be different problems.
alx9r commentedon Jun 20, 2018
Ilya (@iSazonov) I'm not seeing the dramatic speed difference you reported. Perhaps the specifics of the .csv file matter. Here is my test code:
These are the results for Windows PowerShell and PowerShell core, respectively:
Peak memory usage for the test runs was as follows:
iSazonov commentedon Jun 20, 2018
Yes, but Windows PowerShell frees the memory so quickly that sometimes memory consumption can not be seen.
I also see that in your test PowerShell Core is much slower.
rthardin commentedon Jun 29, 2018
I did a bit of iterative testing with a smaller CSV file (104866 bytes). On my system, the results show that Import-Csv performance does vary between back-to-back runs. The minimum runtime was 71 ms and the maximum was 192 ms. It looks like the runtime would decrease each time the GC came along. I'm running PowerShell inside a Docker container (
mcr.microsoft.com/powershell:centos-7).I understand this issue was filed based on processing much larger input files (>100 MB), so I hope these findings are not a distraction; I thought the findings may still be relevant.
source.csv.txt
7112_results.csv.txt
iSazonov commentedon Jun 30, 2018
Ryan Hardin (@rthardin) Thanks for great tests! Could you please continue and test on Windows - for PowerShell Core and Windows PowerShell for comparison?
rthardin commentedon Jul 2, 2018
Ilya (@iSazonov) Unfortunately I don't have the time to spare at the moment, but the test script is posted above for others to try.
iSazonov commentedon Jul 3, 2018
Updated scripts for testing
I started with
Import-Csvand temporary disable output in the C# code. Results was well. So I guess that root of problems in creating PSObject and next two tests confirm this. Windows PowerShell is 30-100 percent faster.It's unclear where the problem is - in PowerShell Core or in .Net Core.
/cc Steve Lee (@SteveL-MSFT) Dongbo Wang (@daxian-dbw)
SteveL-MSFT commentedon Jul 10, 2018
Ilya (@iSazonov) to see if we slowed down creating PSObjects (looking at the Import-CSV cmdlet, it's really just adding NoteProperty members to a PSObject), I ran this test:
Windows PowerShell 5.1 consistently took around 15.7s on my machine. PSCore6.1-3 consistently took around 8.4s, so about twice as fast.
Will have to investigate more where the bottleneck is.
41 remaining items
vancem commentedon Aug 28, 2018
If you have symbols to system.management.Automation, setting up you symbol path (File -> Set Symbol Path) and source path (File -> Set Source Path), and then you can right click on a node name and select Goto Source, and PerfView will take you to the line (attributed with metric). This allows you to see exactly what line is involved.
Note that inlining can often make it hard to follow because the name in the source is really the caller (or caller's caller …). Having the line number (which by the way is approximate, it may be the line before as well), is helpful to disambiguate.
If you ever get suspicious about things, you can fall back to the debugger. Set breakpoints (probably with hit counts, every 1000 or so) for some of the locations that PerfView pointed you at and you can see if they agree with the debugger.
I have looked at lots of traces, and I have only rarely seen something where a name could not be explained by inlining only very, very rarely (and it could have been me misinterpreting the code). If by checking with the debugger, you believe you have found such a case, I would need all the source, PDBs and repro information to really investigate the issue.
iSazonov commentedon Aug 29, 2018
Vance Morrison (@vancem) We haven't published PDB files for RC1. In PerfView log I saw that it search crossgen.exe and coped the utility in startup directory - right? After that I can see entry points in system.management.Automation
SteveL-MSFT commentedon Jun 20, 2019
Ilya (@iSazonov) now that we have moved to .NET Core 3.0, can you rerun your perf test?
iSazonov commentedon Jun 20, 2019
I'm even afraid to think about it :-))))
Will do.
iSazonov commentedon Jun 20, 2019
daxian-dbw commentedon Jun 20, 2019
Ilya (@iSazonov) So the perf issue with
Import-Csvis now gone after moving to .NET 3.0 preview? What do you mean byone columnand700 columns?iSazonov commentedon Jun 20, 2019
Dongbo Wang (@daxian-dbw) After Staffan Gustafsson (@powercode) improvements for PSObject all cmdlets works faster with the objects and make less allocations.
After moving to .Net Core 3.0 we get better GC. Now GC does cleanups even better .Net Framework (I say about the tests I did here). Perhaps .Net Core 3.0 add a performance too but I don't compare with previous PowerShell Core released versions.
In my tests I generate csv files. In first test the csv file consists of one column. Second - 700 columns. The first test shows a general increase in performance (I would assume that most of it comes from .Net Core 3.0). Second one explicitly shows an increase in performance which comes from Staffan Gustafsson (@powercode) PR.
SteveL-MSFT commentedon Jun 20, 2019
Ilya (@iSazonov) so can we close this?
iSazonov commentedon Jun 21, 2019
We get great progress for Import-Csv cmdlet so I close the issue.
Make sense to open new issues if we will find another scenarios with bad performance.
(Although I would like to have something to see performance history - improvements and regressions after new commits)
daxian-dbw commentedon Jun 24, 2019
Absolutely. We need to have some perf tests that serve as benchmarks to help us see the trend. Currently we have none of those tests. Opened #9996