perf: use hashmap in owned object to optimize search performance#156
Merged
Conversation
b1a8e9b to
78ee8ba
Compare
liuq19
reviewed
Feb 5, 2025
| { | ||
| let mut map = tri!(serializer.serialize_map(Some(o.len()))); | ||
| for (k, v) in o.iter() { | ||
| tri!(map.serialize_key(k.as_str())); |
Collaborator
There was a problem hiding this comment.
not sort the keys, pls add the unittest
Collaborator
Author
There was a problem hiding this comment.
I use the btreemap for keys' order and add the unittest for it
liuq19
approved these changes
Feb 5, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What type of PR is this?
perf: use hashmap in owned object to optimize search performance
Check the PR title.
(Optional) Translate the PR title into Chinese.
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
Sonic has a disadvantage compared to serde. Its object type search and insertion performance is O(n), which is determined by the underlying data structure.
To align performance to O(1), sonic objects also need to use hashmaps.
Specifically, sonic's data structures are divided into shared and owned. The former is used in the parse stage and has many internal optimizations. It is not suitable to directly replace the data structure for the time being.
The owned data structure can be directly replaced by hashmap for maintenance. At the same time, in order to support the sort keys function, btreemap is used to make performance tradeoffs for sorting and other operations.
zh(optional):
(Optional) Which issue(s) this PR fixes:
(optional) The PR that updates user documentation: