Repository navigation
Closed
Labels
Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issuesWG-Engine-Performancecore PowerShell engine, interpreter, and runtime performance
Description
Steps to reproduce
$JSON = @"
{
"configGlossary:installationAt": "Philadelphia, PA",
"configGlossary:adminEmail": "ksm@pobox.com",
"configGlossary:poweredBy": "Cofax",
"configGlossary:poweredByIcon": "\/images\/cofax.gif",
"configGlossary:staticPath": "\/content\/static",
"templateProcessorClass": "org.cofax.WysiwygTemplate",
"templateLoaderClass": "org.cofax.FilesTemplateLoader",
"templatePath": "templates",
"templateOverridePath": "",
"defaultListTemplate": "listTemplate.htm",
"defaultFileTemplate": "articleTemplate.htm",
"useJSP": false,
"jspListTemplate": "listTemplate.jsp",
"jspFileTemplate": "articleTemplate.jsp",
"cachePackageTagsTrack": 200,
"cachePackageTagsStore": 200,
"cachePackageTagsRefresh": 60,
"cacheTemplatesTrack": 100,
"cacheTemplatesStore": 50,
"cacheTemplatesRefresh": 15,
"cachePagesTrack": 200,
"cachePagesStore": 100,
"cachePagesRefresh": 10,
"cachePagesDirtyRead": 10,
"searchEngineListTemplate": "forSearchEnginesList.htm",
"searchEngineFileTemplate": "forSearchEngines.htm",
"searchEngineRobotsDb": "WEB-INF\/robots.db",
"useDataStore": true,
"dataStoreClass": "org.cofax.SqlDataStore",
"redirectionClass": "org.cofax.SqlRedirection",
"dataStoreName": "cofax",
"dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver",
"dataStoreUrl": "jdbc:microsoft:sqlserver:\/\/LOCALHOST:1433;DatabaseName=goon",
"dataStoreUser": "sa",
"dataStorePassword": "dataStoreTestQuery",
"dataStoreTestQuery": "SET NOCOUNT ON;select test='test';",
"dataStoreLogFile": "\/usr\/local\/tomcat\/logs\/datastore.log",
"dataStoreInitConns": 10,
"dataStoreMaxConns": 100,
"dataStoreConnUsageLimit": 100,
"dataStoreLogLevel": "debug",
"maxUrlLength": 500
}
"@
$Count = 39999
$jsonarr = "[" + (($json + ",") * $Count) + $json + "]"
[system.gc]::Collect()
write-host ""
write-host ""
write-host "JSON -- Objects: $($Count + 1)"
write-host "JSON -- Length: $($jsonarr.length / 1024 / 1024 ) Megabytes"
$BeforeMemory = $((get-process -pid $PID).WorkingSet)
[void] (convertfrom-json $jsonarr)
$AfterMemory = $((get-process -pid $PID).WorkingSet)
$MemoryDiff = $AfterMemory - $BeforeMemory
write-host "Memory Usage -- Before: $($BeforeMemory / 1024 / 1024) Megabytes"
write-host "Memory Usage -- After: $($AfterMemory / 1024 / 1024) Megabytes"
write-host "Memory Usage -- Difference: $($MemoryDiff / 1024 / 1024) Megabytes"
write-host "Memory Usage -- Multiple: $($MemoryDiff / $jsonarr.length)"
output:
JSON -- Objects: 40000
JSON -- Length: 67.4819955825806 Megabytes
Memory Usage -- Before: 210.8359375 Megabytes
Memory Usage -- After: 1240.90625 Megabytes
Memory Usage -- Difference: 1030.0703125 Megabytes
Memory Usage -- Multiple: 15.2643724241892
Actual behavior
Powershell Core ends up with 1 GB of memory used and peaks to 1.6 GB of memory utilization during convertfrom-json
Expected behavior
Powershell Core shouldn't need 1.6 gigabytes of memory to deserialize a 65MB JSON file.
Environment data
Name Value
---- -----
PSVersion 6.1.0-preview.3
PSEdition Core
GitCommitId v6.1.0-preview.3
OS Microsoft Windows 10.0.17134
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Metadata
Metadata
Assignees
Labels
Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issuesWG-Engine-Performancecore PowerShell engine, interpreter, and runtime performance
Activity
powercode commentedon Sep 3, 2018
We could consider interning property names.
powercode commentedon Sep 3, 2018
Or, probably better, some name dictionary, were we resue the property names. That should help a lot with json memory consumption.
markekraus commentedon Oct 2, 2018
This is actually a duplicate of #6199 as both commands use the same underlying code path.
iSazonov commentedon Nov 19, 2019
The issue is still present.
/cc david-tap
iSazonov commentedon Nov 19, 2019
After the code review I think we need to migrate to System.Text.Json to get performance benefits.
jszabo98 commentedon Dec 21, 2019
Note that convertfrom-json has no streaming mode like jq. So it will load the whole file into memory, no matter how big it is.
hanneshayashi commentedon Dec 8, 2020
Would be great if it had a streaming mode, like jq, though...
7 remaining items
iSazonov commentedon Jun 27, 2021
See #11198 for information.
strawgate commentedon Jun 27, 2021
I know this is the wrong place to talk about the module but i'll just drop one more note:
I ran the Json tests against ConvertFrom-JsonFast and found a couple of issues that I resolved (I implemented noenumerate, depth, and pipeline support). At this time i have 216/224 tests passing with the only tests failing being tests that check for the exact exception type being thrown. The good news is the performance characteristics are the same with these additional items as it was without them.
I will look into adding pscustomobject support as well. I also need to run the tests for Invoke-RestMethod as well.
While the ConvertFrom-Json test coverage isn't great, it's nice to see that it could be fairly compatible!
iSazonov commentedon Jun 28, 2021
Bill Easton (@strawgate) I guess we have very poor test coverage. It would be great if you added new ones. Also we have some issues for Json cmdlets, please look while you're at the beginning of the journey.
strawgate commentedon Jun 29, 2021
I have a PR here that improves performance but unfortunately does not impact memory utilization: #15684
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 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.