3 ms·
How does all of the cloning affect performance? It feels wasteful to create these short-lived components that are explicitly discarded for slightly modified one
by CGamesPlay 11y ago
How does all of the cloning affect performance? It feels wasteful to create these short-lived components that are explicitly discarded for slightly modified ones, but is that actually a problem?
- svachalek 11y agoI'm not sure of the exact logic it uses, but it appears to me that when React finds a new component in place of an old one of the same class, it just changes the props on the old component (and calls componentWillReceiveProps) which bypasses some of the lifecycle calls. Also, I believe Chrome and Firefox (and hopefully other) garbage collectors use a generational algorithm which makes it very cheap to throw away short-lived objects. Of course it's more efficient just to mutate state, but these factors and other optimizations should mitigate the added cost and I think for most applications, the wasted cycles are not going to be much concern.
- pspeter3 11y agoYou're only cloning the JSON representation of the components, not the component instances.