Open kylpo opened 7 years ago
For the record, I ran a quick test to check memory usage, rendering 100k components that have a method bound using:
this.method = this.method.bind(this)
in the constructorthis.method = () => {}
@bind
from the decko
package above the methodMethod 1 took 240MB Method 2 took 219MB Method 3 took 211MB
I'd be interested in how arrow uses less memory than the constructor bind, because arrow binding is compiled to redefine the method in a closure during every instantiation, whereas constructor binding just calls bind
on a pre-defined prototype method (although there is some overhead and a possible closure created when defining the prototype method). Either way, the decko bind seems to be the least memory intensive. An interested test if anyone cares would be to destroy the components and rebuild them, and see how efficient garbage collection is.
remove arrow function instance methods. Replace with
bind()
in constructor.See https://twitter.com/_developit/status/839189848514826241 and https://twitter.com/_developit/status/839454500490526726 for why.