KEMBAR78
STJ: set initial capacity of JsonObject if known (#96417) by olo-ntaylor · Pull Request #96486 · dotnet/runtime · GitHub
Skip to content

Conversation

@olo-ntaylor
Copy link
Contributor

@olo-ntaylor olo-ntaylor commented Jan 4, 2024

Fix #96417.

@ghost ghost added community-contribution Indicates that the PR has been added by a community member area-System.Text.Json labels Jan 4, 2024
@ghost
Copy link

ghost commented Jan 4, 2024

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: olo-ntaylor
Assignees: -
Labels:

area-System.Text.Json, community-contribution

Milestone: -

@eiriktsarpalis eiriktsarpalis added NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) and removed NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) labels Jan 8, 2024
also, caught one more spot to use the IsCaseInsensitive helper
@eiriktsarpalis eiriktsarpalis marked this pull request as ready for review January 9, 2024 15:06
@olo-ntaylor
Copy link
Contributor Author

olo-ntaylor commented Jan 9, 2024

@eiriktsarpalis thanks so much for your continued help with this PR. I am working on getting internal legal approval for the contributor license agreement.

While we're on the subject, though, I wanted to bounce another idea off you to see if it would be worth investigation: It appears that JsonPropertyDictionary has a ListToDictionaryThreshold which governs whether it uses a List or a Dictionary for the data under-the-hood. I can see that being another potentially avoidable performance hit. Namely, in this new world where we might know the capacity of the JsonObject up-front, and if we know it is more than that threshold (9, currently), then we could avoid creating and then immediately throwing away the internal List data structure and just create the Dictionary straight away.

Does that make sense to you?

EDIT: Specifically, I'm thinking that we may modify the constructor here to skip creating the _propertyList and creating the _propertyDictionary instead if capacity > ListToDictionaryThreshold

@olo-ntaylor
Copy link
Contributor Author

@dotnet-policy-service agree company="Olo, Inc."

@eiriktsarpalis
Copy link
Member

Does that make sense to you?

Possibly. You could try opening a new PR after this one is merged, although this one would probably need a bit of microbenchmarking to back its necessity.

Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks excellent, thank you 🎉

@eiriktsarpalis eiriktsarpalis merged commit 1303c3a into dotnet:main Jan 10, 2024
@olo-ntaylor
Copy link
Contributor Author

This looks excellent, thank you 🎉

Awesome!! Thanks so much for your help on this, @eiriktsarpalis (and @to11mtm)

tmds pushed a commit to tmds/runtime that referenced this pull request Jan 23, 2024
…et#96486)

* STJ: set initial capacity of JsonObject if known (dotnet#96417)

* fix nullable type typo

* just tweaking to run the gh actions again to confirm

* wip/squash. use `TryGetNonEnumeratedCount`/polyfill

* wip. go back to using just a check against ICollection

* wip/squash. remove System.Linq dependency

* wip. avoid adding a new field

* wip/squash. move more of the logic into the ctor

* wip/squash. use static private helper method

* wip/squash. use null-coalescing operator

also, caught one more spot to use the IsCaseInsensitive helper

* wip/squash. use more syntax sugar!

---------

Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
@github-actions github-actions bot locked and limited conversation to collaborators Feb 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Text.Json community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Expose JsonObject constructor that accepts a known-length IReadOnlyCollection to avoid unnecessary array resize operations

2 participants