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
Import-CSV has very high filesize-to-memory consumption ratio of around 50 #7603
Importing a 150 MB CSV file with 50k rows, 700 columns and 5 +/- 3 characters per entry results in a memory consumption of 7GB of the PowerShell process. This is a ratio of around 50 when compared to the file size. I have seen this ratio also with a similar file of smaller size (1.5MB) and therefore think this is a more generic issue not specific to the CSV file structure itself.
$csv=Import-Csv$pathToCsvFiile
Note that this does not happen if I do not assign to a variable or pipe to Out-Null
Expected behavior
Filesize to memory ratio is reasonable (around 10)
Actual behavior
Filesize to memory ratio is around 50
Environment data
Latest daily build and RC1
>$PSVersionTable
Name Value
---------
PSVersion 6.1.0-preview.761
PSEdition Core
GitCommitId 6.1.0-preview.761
OS Microsoft Windows 6.3.9600
Platform Win32NT
PSCompatibleVersions {1.0,2.0,3.0,4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Name Value
---------
PSVersion 6.1.0-rc.1
PSEdition Core
GitCommitId 6.1.0-rc.1
OS Microsoft Windows 6.3.9600
Platform Win32NT
PSCompatibleVersions {1.0,2.0,3.0,4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Christoph Bergmeister (@bergmeister) Could you please test with latest build or RC1? We already added two performance fixes. I guess you will be pleasantly surprised.
Christoph Bergmeister (@bergmeister) I tried with a randomly generated file (600 columns, 50000 lines and 10 MB size) and can not confirm - RC1 works very good (process size is 40 MB at start then reduced to 22 MB in TaskManager).
Ilya (@iSazonov) How did you run it? If I run it using Import-Csv $file | Out-Null there is hardly any memory usage but if I assign it to a variable using $csv = Import-Csv $file I get the big memory allocation that I can only get rid of at the end by calling [System.GC]::Collect()
The memory pressure most likely comes from the cost of PSNoteProperty. Each PSNoteProperty has an overhead of 48 bytes, so when you just store a few bytes per property, that becomes massive.
Reacted by Christoph Bergmeister, Michael Klement and Rain Sallow (/u/ta11ow)
Additional thoughts. The cmdlet works well in Framework where GC free memory more aggressively. .Net Core GC has different behavior. Perhaps we could adjust Core GC settings.
Ilya (@iSazonov) The IDataView looks really promising! But this isn't so much a GC issue. It's about how we store our properties. If you pipe to out-null, we do a lot of work of creating the properties, but they probably stay in Gen0, which is fast to collect. The memory pressure is only noticeable when the data is saved to a variable.
We really hit the degenerated case when we have very many properties, and very little data in each.
I was thinking about a global property cache. I don't know what benefits and problems this will bring. And we could consider IDataView for this cache. Although perhaps there could be a rather simpler structure. Combining this with Simple Case Folding #8120 we would get a huge resource saving.
4 remaining items
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
Activity
thezim commentedon Aug 23, 2018
Dup #7112
bergmeister commentedon Aug 23, 2018
Greg Zimmerman (@thezim) I do not see this as a duplicate because the behaviour in Windows PowerShell was the same.
iSazonov commentedon Aug 23, 2018
Christoph Bergmeister (@bergmeister) Could you please test with latest build or RC1? We already added two performance fixes. I guess you will be pleasantly surprised.
bergmeister commentedon Aug 23, 2018
Ilya (@iSazonov) I tried with the latest daily build and using the RC1 today and there was no noticeable difference.
iSazonov commentedon Aug 23, 2018
Christoph Bergmeister (@bergmeister) Thanks!
Please add results of the comparision in the PR description: memory and speed.
iSazonov commentedon Aug 24, 2018
Christoph Bergmeister (@bergmeister) I tried with a randomly generated file (600 columns, 50000 lines and 10 MB size) and can not confirm - RC1 works very good (process size is 40 MB at start then reduced to 22 MB in TaskManager).
bergmeister commentedon Aug 24, 2018
Ilya (@iSazonov) How did you run it? If I run it using
Import-Csv $file | Out-Nullthere is hardly any memory usage but if I assign it to a variable using$csv = Import-Csv $fileI get the big memory allocation that I can only get rid of at the end by calling[System.GC]::Collect()iSazonov commentedon Aug 24, 2018
Test script
Your issue is not directly related with Import-Csv. Seems we have extra allocations in "=" operator.
powercode commentedon Feb 10, 2019
The memory pressure most likely comes from the cost of PSNoteProperty. Each PSNoteProperty has an overhead of 48 bytes, so when you just store a few bytes per property, that becomes massive.
powercode commentedon Feb 10, 2019
A workaround you can try is to generate a type for the items, and store the data there.
That should be more efficient. You can improve the typing, ints are cheaper than strings for example, but you get the gist.
iSazonov commentedon Feb 10, 2019
Additional thoughts. The cmdlet works well in Framework where GC free memory more aggressively. .Net Core GC has different behavior. Perhaps we could adjust Core GC settings.
powercode commentedon Feb 10, 2019
Christoph Bergmeister (@bergmeister) I created a gist here https://gist.github.com/powercode/19eeb7c65e7542f4f221d54bb487307a where I made that into a function.
powercode commentedon Feb 10, 2019
Ilya (@iSazonov) The
IDataViewlooks really promising! But this isn't so much a GC issue. It's about how we store our properties. If you pipe to out-null, we do a lot of work of creating the properties, but they probably stay in Gen0, which is fast to collect. The memory pressure is only noticeable when the data is saved to a variable.We really hit the degenerated case when we have very many properties, and very little data in each.
powercode commentedon Feb 10, 2019
It would be interesting to play with IDataView and use it in PSObject as another way of storing properties (instead of noteproperties, that is).
iSazonov commentedon Feb 10, 2019
I was thinking about a global property cache. I don't know what benefits and problems this will bring. And we could consider IDataView for this cache. Although perhaps there could be a rather simpler structure. Combining this with Simple Case Folding #8120 we would get a huge resource saving.
4 remaining items
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.