Ivan Akulov, a web performance engineer and consultant, discusses React concurrency in React 18. Topics include time slicing, optimization of hydration, drawbacks of React concurrency, setting suspense boundaries, and their social media account and website for React and performance-related content.
React 18 introduces time slicing, which improves user experience by splitting rendering work into smaller chunks.
Concurrency in React allows for multiple updates to run at the same time, enhancing app responsiveness and mimicking how a CPU handles multiple apps with a single core.
Deep dives
React Concurrency and Time Slicing
React 18 introduces the concept of React concurrency and time slicing. Time slicing is a feature that splits up rendering work into smaller chunks of 5 to 10 milliseconds, allowing the browser to handle user input in between the rendering. By using time slicing, the user experience is improved as the page does not freeze while rendering large components. However, time slicing needs to be enabled in React and properly applied to components. Concurrency in React allows for multiple updates to run at the same time, mimicking how a CPU handles multiple apps with a single core. React prioritizes important updates, such as synchronous clicks, over less important updates. Start Transition is a function in React that can be used to make updates non-urgent, improving app responsiveness. This can be particularly effective in scenarios where rendering large sets of data, such as tables or lists. However, it's important to note that start transition may not work optimally if any component within a set of updates is expensive to render.
Hydration and Concurrent Rendering in React 18
Hydration, the process of making a server-rendered app interactive, has been optimized in React 18 through concurrent rendering. The render phase in React, which converts components into a virtual DOM, can be time-consuming, especially during hydration. Concurrent rendering allows for non-blocking hydration by splitting the initial render task into smaller tasks. This significantly improves page responsiveness and performance. However, there are considerations and potential drawbacks to be aware of when implementing concurrent rendering. The complexity of the React core increases, and misuse of concurrent rendering can lead to performance issues. It's important to properly apply start transition and suspense boundaries to avoid blocking the entire app and ensure efficient hydration. Proper management of rendering boundaries and suspense boundaries can optimize hydration and prevent performance bottlenecks.
Benefits and Drawbacks of React Concurrency and Hydration
React concurrency and time slicing provide several benefits, such as improved user experience, better app responsiveness, and reduced blocking time. By slicing rendering work into smaller chunks, React allows for smoother interaction and faster updates, particularly in apps with large data sets. Concurrent rendering also enhances hydration, making server-rendered apps more performant with faster interactivity. However, there are potential drawbacks to consider. Implementing concurrency increases the complexity of the React core, which may have an impact on overall performance. Additionally, misusing concurrent rendering or not properly managing suspense boundaries can lead to unexpected behavior and performance issues. It's important to weigh the benefits and drawbacks and apply these features appropriately to optimize the React app's performance.
Author Information and Additional Resources
Ivan Alkalov, a web performance engineer and consultant, discusses React concurrency and hydration in this episode. He shares insights from his experience consulting with startups and big companies like Google. Ivan regularly shares his thoughts and tips on Twitter, where he can be found at @iamacool. He also writes case studies and provides performance insights on his blog at threeperf.com. You can find more detailed information and examples from Ivan's writings, which are worth exploring to gain a deeper understanding of React concurrency and optimization techniques.
Learn about the intricacies of React concurrency and performance features, specifically in React 18, with Ivan Akulov, web performance engineer and consultant at PerfPerfPerf.
We want to hear from you! We want to know what you love and hate about the podcast. What do you want to hear more about? Who do you want to see on the show? Our producers want to know, and if you talk with us, we’ll send you a $25 gift card!
Follow us on Apple Podcasts, fill out this form, and we’ll send you free PodRocket stickers!
What does LogRocket do?
LogRocket combines frontend monitoring, product analytics, and session replay to help software teams deliver the ideal product experience. Try LogRocket for free today.
Special Guest: Ivan Akulov.
Remember Everything You Learn from Podcasts
Save insights instantly, chat with episodes, and build lasting knowledge - all powered by AI.