Skip to content

perf: use hashmap in owned object to optimize search performance#156

Merged
liuq19 merged 7 commits into
mainfrom
feat/object_map
Feb 5, 2025
Merged

perf: use hashmap in owned object to optimize search performance#156
liuq19 merged 7 commits into
mainfrom
feat/object_map

Conversation

@Ggiggle
Copy link
Copy Markdown
Collaborator

@Ggiggle Ggiggle commented Jan 23, 2025

What type of PR is this?

perf: use hashmap in owned object to optimize search performance

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(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:

Comment thread src/value/node.rs Outdated
{
let mut map = tri!(serializer.serialize_map(Some(o.len())));
for (k, v) in o.iter() {
tri!(map.serialize_key(k.as_str()));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

not sort the keys, pls add the unittest

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I use the btreemap for keys' order and add the unittest for it

Comment thread src/value/node.rs Outdated
@liuq19 liuq19 merged commit 272ef60 into main Feb 5, 2025
@liuq19 liuq19 deleted the feat/object_map branch February 5, 2025 10:30
@Ggiggle Ggiggle self-assigned this Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants