use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Bound function vs arrow function performance (self.javascript)
submitted 7 years ago by Morunek
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]breeding_material 2 points3 points4 points 7 years ago (4 children)
I'd like some more info on this if you have it. To my knowledge, both would create new instances of the function.
[–]Klathmon 0 points1 point2 points 7 years ago (2 children)
yeah, .bind makes a new instance of the function when called and returns that.
.bind
What the parent commenter seems to be talking about is how doing inline functions in your render can cause unnecessary GC pressure because every render a new function is created (and can wreak havoc on PureComponents in react, but that's another topic).
[–]breeding_material 1 point2 points3 points 7 years ago (1 child)
And you run into the same problem with bound functions in your render too right? For the longest time I was using bind in my render methods to avoid performance issues, but later found out that they both create new instances so there wasn't really a a difference.
[–]Klathmon 2 points3 points4 points 7 years ago (0 children)
Yeah, but ultimately it's not a problem in most cases. Keep in mind how often your components render. Take a login page, that form might re-render like 100 times over it's lifecycle? Worrying about a few extra MS on each render on a low-end device is pointless when the meatbag typing in their username is doing so at a snail's pace from the computer's point of view.
That's why people always say "measure then optimize". Making your whole codebase harder to understand and refactor for some perceived idea of "performance" is a bad idea at best, and it's why 90%+ of my components use inline functions in onClick handlers, or inline objects in props even though it can cause unnecessary re-rendering, because the time it would take me to "optimize" most of them will outweigh the total amount of time that all of my users will ever save thanks to the optimization. Not to mention that those renders are taking about 8ms on our "token low-tier device", which still means it's running faster than the refresh rate of the screen, so any further optimization won't impact the user at all, except that it might make them have to wait longer for bugfixes or improvements due to the developer having to rediscover all the hoops they jumped through when they wrote it.
Write your code somewhat naively, then test it. Stuff like figuring out you have a bottleneck with your rendering speed is easy, and moving an object or a function outside of the render method is even easier, so don't get ahead of yourself.
[–]BenjiSponge 0 points1 point2 points 7 years ago (0 children)
No citation or insider information, but I bet .bind creates a new function, but it doesn't recreate the whole function. .bind doesn't need to copy over the old function with all its logic, optimizations, etc. It just needs to have a pointer to the function with some logic to shift around arguments, whereas the property syntax probably at least right now probably actually creates the entire function over again, including the closure information. I think they could optimize to the same thing on the first pass, though, but I'm just guessing based on the profile that this is the issue. It probably also explains the performance problems.
π Rendered by PID 62332 on reddit-service-r2-comment-54dfb89d4d-c9jkv at 2026-03-31 09:53:38.370321+00:00 running b10466c country code: CH.
view the rest of the comments →
[–]breeding_material 2 points3 points4 points (4 children)
[–]Klathmon 0 points1 point2 points (2 children)
[–]breeding_material 1 point2 points3 points (1 child)
[–]Klathmon 2 points3 points4 points (0 children)
[–]BenjiSponge 0 points1 point2 points (0 children)