Skip to content
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

Memory usage suggestion : reduce unnecessary boxes #2638

Closed
mgravell opened this issue Jan 14, 2022 · 0 comments · Fixed by #2639
Closed

Memory usage suggestion : reduce unnecessary boxes #2638

mgravell opened this issue Jan 14, 2022 · 0 comments · Fixed by #2639

Comments

@mgravell
Copy link
Contributor

Currently, if you deserialize a model with lots of, say, boolean values in it: you get a lot of boxed booleans on the heap, from multiple sources, but mostly:

  • JsonTextReader.SetToken
  • new JValue(object, [JTokenType])

Suggestion:

  • create static readonly boxed objects for a range of likely primitive values
  • use the shared boxed copies in preference to vanilla boxing
  • avoid naïve and unnecessary new JValue(object) (side benefit: avoid some extra type testing)

This would significantly help (based on real testing with dotMemory etc) both the temporary gen-zero allocations of in-flight objects and the cost of retained JToken etc trees.

Happy to submit a PR if useful.

mgravell pushed a commit to mgravell/Newtonsoft.Json that referenced this issue Jan 14, 2022
JamesNK pushed a commit to mgravell/Newtonsoft.Json that referenced this issue May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant