-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Introduce streaming for ConvertFrom-Json #15695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
strawgate
wants to merge
10
commits into
PowerShell:master
from
strawgate:json-optimization-streaming
Closed
Introduce streaming for ConvertFrom-Json #15695
strawgate
wants to merge
10
commits into
PowerShell:master
from
strawgate:json-optimization-streaming
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…lets pass it directly instead of having to worry about properties
Emdot
reviewed
Jun 29, 2021
src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs
Outdated
Show resolved
Hide resolved
Emdot
reviewed
Jun 29, 2021
src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs
Outdated
Show resolved
Hide resolved
22 tasks
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Review - Needed
The PR is being reviewed
WG-Cmdlets-Utility
cmdlets in the Microsoft.PowerShell.Utility module
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Summary
This PR performs special handling for a particular json use-case where the response body is an array. This detects that situation and deserializes the array one object at a time. This greatly improves runtime characteristics and reduces memory usage when the json is an array of objects while preventing us from having to implement our own full json parser.
This PR does not improve performance of parsing a single large dictionary.
PR Context
ConvertFrom-Json is a core cmdlet for anyone using Powershell for Web APIs. The Cmdlet has very poor runtime characteristics. It takes a long time to deserialize json compared to other deserializing in other languages and it uses a lot of memory to deserialize (15x the size of the json).
This PR on its own increases memory usage as compared to master. Combined with #15684 this PR cuts memory usage and runtime by more than half.
Benchmark for 100MB JSON file:
Master
ThisPR Alone
#15684
ThisPR + #15684
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).