-
Notifications
You must be signed in to change notification settings - Fork 31
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
New API for calcExtents (Issue #44) #45
Conversation
…y, -Infinity] and {} rather than null, don't change input args
Sorry for the delay on this. I made some minor tweaks that I'll go over and let me know your thoughts. I pushed to this branch but if you give me push access to your forked repo I can add those commits onto this PR to keep it all nice and organized. Let me know what you think on any and all!
Thanks again for making so much progress on this and sorry for the delay in reviewing it – I've had a busy few weeks. |
Looks like if you do this, then I can push directly to your branch
|
|
Those changes all sound good to me. I'll take a look at the code in a moment. Particularly the It's strange - I hadn't unchecked "Allow edits from maintainers". I've tried unchecking and re-checking it to see if that helps, but I guess it won't. I've also sent you an invitation to edit my fork. |
I've had a read through your edits, but I haven't tried downloading and running them. They all look great to me. A couple of thoughts, probably not important:
|
I'll go over it closely and double check it. I haven't done any benchmarking but if you had some time to put something together comparing the new vs the old version that would be great. What's the performance hit for using currying? That |
Cool that worked and I pushed those commits to this branch |
I don't know the proper way to do benchmarking, but I tried running this script to get an idea of how slow or fast import calcExtents from './src/lib/calcExtents.js';
const x = {args: [[], {z:d=>d}], expected: {z: [0, 5]}};
for (let i=0; i<500000; i++) {
x.args[0].push(0);
x.args[0].push(5);
}
for (let i=0; i<1000; i++) {
console.log(calcExtents(...x.args));
}
console.log(x.expected); (It creates an array with a million elements, then runs The new version takes 15.6 seconds on my laptop, the non-curried version is about the same, and the pre-pull-request version takes only 5.55 seconds. So, it's about 15 ms vs 5 ms for each traversal over the million elements (although perhaps the first run of My feeling is that the slowdown is worth it to have slightly more readable code, since 1000000-element arrays are uncommon. What do you think? I can inline the min and max functions again if you think the slowdown is a problem. |
I tried running |
Interesting! I'll take a look and see where the differences occur I'm kinda curious. |
I put together three versions on this branch and compared them to the original.
I'm really curious why the new api takes so long. maybe the |
Nevermind, I was doing something stupid. These are the results:
I included the news test for modifying data and it passes – but I didn't really change that much from the original |
I totally agree with your changes. Sorry that the min/max functions were a bit of a waste of time. I think your current version of the function is great, and as far as I can tell it's correct. My only tiny further suggestion is in the following diff: It's possibly a tiny bit more readable? It also seems to be marginally faster (newX is the modified version):
But I think the code is great as it is and there's no need to make this further change unless you really feel like it! |
PS it's interesting that |
Cool thanks for looking at it! Yes I like that |
Done :-) |
Thanks! I'll prep the examples and everything and merge this in. I'll do some additional testing on the existing examples too, just in case. |
Issue #44
This PR changes the API of calcExtents to use an object rather than an array of accessor functions. It also fixes a bug where the data passed could be modified (in rare circumstances).
I have made a number of changes to be behavior. Most of these are described in this comment. In addition:
I'm not confident that all of these are good decisions, but hopefully the code is helpful in some way!