17. Inefficient Renders
// Before
render() {
return (
<ul>
<li>Hollywood</li>
<li>Pasadena</li>
</ul>
)
}
// After
render() {
return (
<ul>
<li>Santa Monica</li>
<li>Hollywood</li>
<li>Pasadena</li>
</ul>
)
}
• React uses recursive diff’ing
• Inserting at the beginning of the list means
rendering the whole tree again
18. Inefficient Renders
// Before
render() {
return (
<ul>
<li>Hollywood</li>
<li>Pasadena</li>
</ul>
)
}
// After
render() {
return (
<ul>
<li>Santa Monica</li>
<li>Hollywood</li>
<li>Pasadena</li>
</ul>
)
}
• React uses recursive diff’ing
• Inserting at the beginning of the list means
rendering the whole tree again
• Best algorithms have a time complexity O(n3)
19. Inefficient Renders
// Before
render() {
return (
<ul>
<li>Hollywood</li>
<li>Pasadena</li>
</ul>
)
}
// After
render() {
return (
<ul>
<li>Santa Monica</li>
<li>Hollywood</li>
<li>Pasadena</li>
</ul>
)
}
• React uses recursive diff’ing
• Inserting at the beginning of the list means
rendering the whole tree again
• Best algorithms have a time complexity O(n3)
• 1000 elements === 1billion comparisons
21. The Solution?
• Heuristics - using shortcuts today to
solve the problems of tomorrow
https://facebook.github.io/react/docs/reconciliation.html
22. The Solution?
// Before
render() {
return (
<ul>
<li key="Hollywood">Hollywood</li>
<li key="Pasadena">Pasadena</li>
</ul>
)
}
// After
render() {
return (
<ul>
<li key="Santa Monica">Santa Monica</li>
<li key="Hollywood">Hollywood</li>
<li key="Pasadena">Pasadena</li>
</ul>
)
}
• Heuristics - using shortcuts today to
solve the problems of tomorrow
• Using “key” allows React to match
children in the original tree with
children in the subsequent tree
https://facebook.github.io/react/docs/reconciliation.html
23. The Solution?
// Before
render() {
return (
<ul>
<li key="Hollywood">Hollywood</li>
<li key="Pasadena">Pasadena</li>
</ul>
)
}
// After
render() {
return (
<ul>
<li key="Santa Monica">Santa Monica</li>
<li key="Hollywood">Hollywood</li>
<li key="Pasadena">Pasadena</li>
</ul>
)
}
• Heuristics - using shortcuts today to
solve the problems of tomorrow
• Using “key” allows React to match
children in the original tree with
children in the subsequent tree
• Keys only need to be unique to
siblings not the global scope
https://facebook.github.io/react/docs/reconciliation.html
25. How is Fiber Different?
• A fiber is a JavaScript object that contains information
about a component, its input, and its output.
26. How is Fiber Different?
• A fiber is a JavaScript object that contains information
about a component, its input, and its output.
• Allows delaying the render of components by using a
priority system