Skip to content

Conversation

@strawgate
Copy link
Contributor

@strawgate strawgate commented Jun 29, 2021

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

@ghost ghost assigned rjmholt Jun 29, 2021
@strawgate 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

ghost commented Jul 7, 2021

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

@rjmholt rjmholt added the WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module label Aug 11, 2021
@strawgate strawgate closed this Aug 25, 2021
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants