-
Notifications
You must be signed in to change notification settings - Fork 84
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
Consider using IndexMap: json order is random after a 33 keys in map #378
Comments
Hi ritchie, by specification json objects are unordered sets but that also doesn't mean it has to be unordered. the order for the first 32 keys is an implementation detail. We use halfbrown that uses a simple vector for up to 32 elements which makes small objects, which are frequent with json, extremely fast and small (memory wise). That's just for background :). Generally if we can make it optional and preserve the current behaviour I'm in, giving people more options is nice! A feature to watch out for is known-key, it is quite powerful when using lookups of the same key repeatedly and it'd be good to preserve it I could see a few ways to make this work:
|
Ah, given that you also maintain For me a feature flag would be fine. So that would be option 2. 👀 |
perfect, sounds like we got a plan then :)! Also #377 might be of interest for you, it keeps order as long as no mutations are done already (and it should "just work" with index map as well) |
Great! Thanks for being receptive to this. :) For #377, I need a little bit more context. 😅 What does it do? What is the semantic difference between a borrowed value and a tape? |
the borrowed value is a fully mutable DOM equivalent to serde_json::Value; the tape value is a flat structire (a single vec) that represents the JSON document, since it has no nesting and doesn't require extra allocations, inserts, etc it is significantly faster. the downside is that the tape is not easily mutable; the lazy value bridges the gab between the two :) |
This python snippet wouldn't round trip if simd-json was used:
This is because
Object
uses a hashmap which doesn't preserve the order of the json string keys. This can be resolved by usingI would like to consider using indexmap, which has excellent performance, AND guarantees index order.
This issue was discovered in: pola-rs/polars#17439
If this is accepted, I am willing to make a PR.
The text was updated successfully, but these errors were encountered: