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

Improve performance by allow unordored HashMap #205

Closed
Stargateur opened this issue Jul 27, 2020 · 3 comments
Closed

Improve performance by allow unordored HashMap #205

Stargateur opened this issue Jul 27, 2020 · 3 comments

Comments

@Stargateur
Copy link

Toml crate have a preserve_order feature to handle case where it's desired to keep order of field. While bson already handle this it could be nice to have a no_preserve_order feature, this could increase performance if preserve order is a cost (I assume it is).

@saghm
Copy link
Contributor

saghm commented Jul 27, 2020

One thing to note is that unlike JSON, BSON is an ordered format. This is necessary for certain cases of usage in MongoDB drivers; for example, when sending a command to the server, the first key is always the name of the command. If the name of the command was not the first key, the server would at best return an error due to an invalid command name. Because of this, it wouldn't be possible for the driver to depend on the BSON library with a no_preserve_order feature. While this could potentially be mitigated by having a separate unordered type that users could pass in, I'm not sure that doubling the size of the Document API exported by the driver is worth the slight gains due to removing ordering in the documents that a user passes in. I think a larger gain would be to add some sort of raw Document type (like what's proposed in #136) so that users who don't need arbitrary lookup of key/value pairs can avoid the cost of deserialization.

@Stargateur
Copy link
Author

🤕 I think the documentation never mention it, but now you say it, it's obvious.

I will add this to my fictional list (still short 😄) of design choice of mongo that make me sad. Guess there is not much to do so, BSON crate is primary used for mongo and I agree mongo driver starting to mix both version would be annoying to use.

#136 look to allow more flexibility, probably more verbose, the code need some doc for me to fully understand the possibility.

@immno
Copy link

immno commented Sep 9, 2024

I also have the preserve_order problem. In my application, I use a lot of serde_json Value, and there are millions of them in memory. If I use no_preserve_order, it will save 48 bytes the storage space. I also rely on Value to nest other data structures, which will affect my performance and memory.

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

No branches or pull requests

3 participants