-
Notifications
You must be signed in to change notification settings - Fork 15
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
Allow passing a comparator function to the deterministic
option
#49
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much, this is already looking very good!
I think it's possible to simplify it a tad, so I left a few comments. I'll merge it with those addressed.
Hi @BridgeAR, thanks for the review. Happy to use the suggested changes. Circumventing the fast-path is a trade-off between performance and simplicity for the purpose of not having to implement the default/fallback comparator function, I guess? Edit: Edit 2: |
Co-authored-by: Ruben Bridgewater <ruben@bridgewater.de>
Co-authored-by: Ruben Bridgewater <ruben@bridgewater.de>
Co-authored-by: Ruben Bridgewater <ruben@bridgewater.de>
Co-authored-by: Ruben Bridgewater <ruben@bridgewater.de>
Co-authored-by: Ruben Bridgewater <ruben@bridgewater.de>
@flobernd thank you for the contribution! The benchmark depends on the concrete input. Objects are often not that badly sorted and the performance depends on the length and the necessary steps needed to sort the input. The native implementation is faster but there's a cost to cross the JS / C++ layer and that's why it's favorable for a couple of inputs to use the JS implementation. For the the comparator it's probably always favorable to use the native implementation as the function calls needed can be better optimized in the native implementation. Would you mind sharing your input that you used? |
@BridgeAR I see, that makes sense. The test data was just the simple a,b,c object from the custom comparator test that I modified to run multiple times in a loop. A rather bad way of benchmarking, I know 😝 Just wanted to get a feeling for the performance, but given the bad test methodology and the very simple input object, the result was probably far from being accurate or even representative for a real world workload. |
@BridgeAR Would it be possible to push the 2.5.0 release to NPM? 🙂 |
Hi @BridgeAR, sorry to bother you with this again:
We can as well publish a clone, if you are busy etc. |
Hey @flobernd, I am going to to publish it in a few days. I am currently not at home but my publishing token is at home. |
Thanks a lot @BridgeAR ! |
@flobernd I just published the new version |
Thank you @BridgeAR 🙂 |
This allows to use a custom comparator function for the deterministic sorting of object keys.
Closes #48
@BridgeAR I'm not very familiar with JS, so please feel free to suggest improvements 🙂