Skip to content

Introduce streaming for ConvertFrom-Json - #15695

Closed
Bill Easton (strawgate) wants to merge 10 commits into
PowerShell:masterfrom
strawgate:json-optimization-streaming
Closed

Bill Easton (strawgate) wants to merge 10 commits into
PowerShell:masterfrom
strawgate:json-optimization-streaming

Conversation

@strawgate

@strawgate Bill Easton (strawgate) commented Jun 29, 2021 •

Copy link
Copy Markdown
Contributor

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

  • Memory Usage: 1079.3671875 MB
  • Runtime: 7256.4268 ms

ThisPR Alone

  • Memory Usage: 1477.83203125 MB
  • Runtime: 6574.552 ms

#15684

  • Memory Usage: 1077.58203125 MB
  • Runtime: 3885.0489 ms

ThisPR + #15684

  • Memory Usage: 451.390625 MB
  • Runtime: 3077.3673 ms

PR Checklist

@strawgate Bill Easton (strawgate) changed the title WIP: Introduce streaming for ConvertFrom-Json Introduce streaming for ConvertFrom-Json Jun 30, 2021
@ghost ghost added the Review - Needed The PR is being reviewed label Jul 7, 2021
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

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 general cmdlet issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants