-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
use Buffer.from if available(usually in node.js environments) in _.isEqual #2881
base: master
Are you sure you want to change the base?
Conversation
…ter checking in case of objects which can be cast to buffer
Hi @jgonggrijp Julian, hope you are doing well. So I made a draft PR to use native Buffer.from in isEqual function for buffers and related objects if available(usually in node.js environments) as per discussion here. |
Thank you Saikat, I'm doing well and I hope you are doing well, too. Your code looks sensible and I like the care you've put into benchmarking this. We need to push the CPU a bit harder, though. Imagine building an application that makes a single comparison between two typed arrays. That application might save 20 ms. Nobody is going to care about that. If somebody wants to save time (and energy) on comparing typed arrays, it's probably because she is comparing thousands or even millions of pairs of typed arrays. She's hoping to shave off at least a few seconds in total, or to improve her throughput by thousands of comparisons per second. JavaScript engines behave differently when you repeat code very often. The more often a piece of code repeats, the harder they try to make it run as fast as possible. Those 20 ms you need for a single comparison, might be sufficient for 100 comparisons or more once JSCore, V8 or SpiderMonkey has fully optimized the code. The performance difference between the existing and the new implementation is likely to change under those circumstances, too. So please extend your benchmarks to make a minimum number of repetitions (I suggest at least 10k) and also to continue repeating until at least a whole second has passed. This will make them better represent a situation where performance actually matters. Please also make sure that you vary the buffers that are compared between repetitions. If program flow is the same every time, an optimizing engine might notice that at some point and start cheating. An example of a microbenchmark that follows these recommendations can be found over here. Some context for that benchmark over here (you might need to click "show resolved" in order to see my comment about the benchmark). When you notice a significant difference between the first run and subsequent runs on your local machine, it is likely that disk latency is playing a role. In that case, you should actually ignore the first run, because a significant portion of its CPU time is spent on waiting for the file system. |
Thanks Julian @jgonggrijp for your detailed comments and the link to the benchmark. Let me check that out and come back to you maybe sometime tomorrow. Edit: I found https://nodesource.com/node-by-numbers, any more ? |
I don't know about usage statistics between Node versions, but I don't think it is very important, either. I'd like to suggest to focus on recent versus old instead, because that is how usage tends to develop; if the performance difference between existing and new implementation declines towards newer Node versions, that might suggest that the optimization has little added value in the long run. I'm getting ahead of the facts, though. Let's just look at the numbers first. |
Hi @jgonggrijp Julian , I probably won't get time today to work on this. Let me come back to you maybe tomorrow. |
…equals directly after checking if its a function and also do isFunction check before bind as bind may throw exception if not a function
@sktguha Best wishes for 2021. Any updates on this PR? |
Oh hi @jgonggrijp . Happy new year to you too 🙂 |
Alright, so if I understand correctly, the link you put up is https://github.com/sktguha/underscore-isequal-tests and my comments on that benchmark still need to be addressed, which you'd happily defer to somebody else. If at second thought, you'd rather drop this PR, that's fine by me; no hard feelings. |
@jgonggrijp oh no no , I do intend to come back to this 🙂 I mean otherwise someone can take over. feel free to! . Why would I want to drop it 🙂 ? |
you could tag people here interested to tak over I guess |
@sktguha No I'm not on a deadline (not for this particular PR at least)! Please take your time. I was asking rather directly whether you still want to continue with this, just to be very clear. If your answer is "yes but probably later", that's totally fine by me. |
@jgonggrijp ok understood, "yes but probably later" yup that's what I would say. To add it, happy to hand it over if anyone is interested 🙂 |
@jgonggrijp btw just curious, do you work in USA timezone ? |
oh ok, you seem to be based in Netherlands, well better timezone overlap with India 🙂 |
Yes, Netherlands. I'm a night owl though, so that might decrease the overlap again. However, if you'd like to chat about something, you can find me on Gitter. |
oh that's awesome. can you post your gitter username maybe ? I have made an account there with this github login only. |
I found you and I left you a message on Gitter. |
use Buffer.from if available(usually in node.js environments) in _.isEqual for faster checking in case of objects which can be cast to buffer