Possible over-optimization #128
Replies: 4 comments
-
Behold, science! I made an experimental branch to explore this idea a bit. Here's the relevant commit: db7c646?w=1 And here are benchmarks for the before each approach: And here's how the memory utilization compares (experimental build is on the right): The version with re-declared variables is trivially more efficient, both with with CPU and memory usage. The code is also far more readable and maintainable. Indeed, I got too clever and over-optimized here. But now we have the metrics to prove it! I'll release the improved version as 2.14.2 shortly. 🙂 |
Beta Was this translation helpful? Give feedback.
-
2.14.2 has been shipped! |
Beta Was this translation helpful? Give feedback.
-
Hey @jeremyckahn I hope it's ok to revive this discussion now - just to tell you thank you for posting this and your observations/benchmarks! Very useful to understand this kind of over optimizations and how they scale/don't scale. Thanks again for your work on Shifty and on these kind of optimisations! |
Beta Was this translation helpful? Give feedback.
-
I'm glad to hear you got something out of this exploration as well, @4ian! It was fun to go super deep on performance analysis like this. I don't often get to do that! 😄 |
Beta Was this translation helpful? Give feedback.
-
I uploaded this video detailing the performance improvements to Shifty in 2.14.0. At the linked point in the video, I explain the reused variables used in Shifty's private helpers. For instance, here:
shifty/src/tweenable.js
Lines 54 to 98 in af71d52
This is an admittedly weird way to write JavaScript, but the basic idea is that these functions' variables are being reused from invocation to invocation. I assumed this would be faster, as the variables are being reused rather than redeclared many times in a tick. However, it's not so cut and dry. Take a look at this Gist that benchmarks this technique, and its results:
The "Closured" function (the one with the reused variables) is slightly faster for fewer iterations, but starts to become slower for greater numbers of them. This is the opposite of what I expected.
I'll experiment a bit with which approach yields better results in Shifty. If it seems that the standard form is faster, I'll switch to that as the code would be far more maintainable. I'll update this thread with what I learn!
Beta Was this translation helpful? Give feedback.
All reactions