Overcoming Performance Limitations in React Components for Low-end Devices
From Author:
In this session, I will discuss our experiences in overcoming performance limitations while developing React components for web apps on low-end embedded devices such as Smart TVs. I will share actual application cases from the development of millions of webOS Smart TVs and show how we improved user input response and app launch time. The ideas and techniques shared will be beneficial to developers facing similar challenges.
This talk has been presented at React Summit 2023, check out the latest edition of this React Conference.
FAQ
The talk focuses on two key performance metrics: app launch time and scrolling performance.
LG Electronics improved app launch time by using pre-rendering techniques and the VSnapshot plugin, which resulted in a more than 30% faster launch time for their apps.
Pre-rendering involves generating the HTML for the first screen during the build time using the renderToString function, and then packaging the app with this HTML to improve performance.
The VSnapshot plugin is a specific operation used by LG Electronics to speed up app launch times. It requires a MKSnapshot binary tied to a specific version of Chromium and helps in reducing launch times by more than 30%.
Scrolling performance is improved using virtualization techniques and native scrolling. Virtualization recycles DOM elements to handle long lists efficiently, and native scrolling delegates the scrolling task to the browser to maintain 60 FPS.
The Virtual List component is a technique used to handle very long list items by recycling DOM elements, thus improving scrolling performance by reducing the number of DOM elements created.
Translate mode involves moving the container div using the Translate3D function and virtualizing items within a Request animation frame to handle scrolling efficiently.
NativeMode delegates the scrolling task to the browser, eliminating the need for distance calculations and container movement within the Request animation frame, thus achieving 60 FPS performance.
Remote control keys can be used for scrolling by implementing an onKeyDown event handler that calculates the proper coordinate and calls the scrollTo() function to move the container element smoothly.
Enact is a React-based app framework designed by LG Electronics for TV UI components, remote control navigation, accessibility, and internationalization. It is used on millions of webOS TVs, including LG OLED TVs.
Video Transcription
1. Introduction to Overcoming Performance Limitations
I will talk about overcoming performance limitations in React components for low-end devices. Low-end devices such as smart TVs and set-top boxes often have limited hardware performance. In this talk, I will focus on app launch time and scrolling performance.
Hi, everyone. I'm so excited to talk about overcoming performance limitations in React components for low-end devices. My name is Seungho from LG Electronics and I'm leading the Enact framework. Enact is a React-based app framework designed for TV UI components, remote control navigation, accessibility, and internationalization. It's used on millions of webOS TVs, including the apps you see on LG OLED TVs.
In this talk, I will share our experiences in overcoming performance limitations when we create a React component for those apps. Low-end devices such as smart TVs and set-top boxes often have limited hardware performance. This makes it challenging to develop high-performance web apps on these devices. There are lots of performance metrics, but in this talk, I will focus only on app launch time and scrolling performance.
2. Improving App Launch and Scrolling Performance
App launch time is crucial for delivering a native quality experience on smart devices. We improved performance through pre-rendering, generating HTML at build time, and using VSnapshot for system apps. Scrolling performance is critical for media-type apps on TV devices. We improved it by creating the Virtual List component.
Let's talk about app launch time first. App launch time is one of the most important performance metrics on smart devices to deliver a native quality experience to users. When developing the In-App Framework, the biggest challenge was to provide fast and smooth performance so that the user can't tell if it is a native web or web app. So how did we improve from left to right? To obvious, we applied pre-rendering. You've probably seen this picture before. It's from the web.dev for explaining the server-side rendering.
Since our goal is to develop pre-installed apps for the device, we choose a structure that is closer to CSR with pre-rendering. This is a very simplified version of our pre-rendering flow. This is a typical React App build. We transpile the JSX and ESCX code and package it. At this build time, we use the node server to call the renderToString function. This generates the HTML for the first screen and we package the app with this HTML. When we run the app, we call the hydrateRoot function instead of the createRoot function. To support over 200 locales, we generate pre-rendered HTML for each locale at build time. Duplicate content is saved as multi.html. A localeMap.json file maps the locale to the HTML file and an ebin4.json file, which is the M-metadata, specifies the HTML file as the main entry point. Pro-tip, we use VSnapshot for system apps. This is a highly specific operation and definitely isn't ideal for everybody. However, it is useful in certain scenarios, and this will help simplify the process. We made the snapshot plugin, and it assumes usage of React. This plugin requires you to obtain a MKSnapshot binary. It is usually tied to the specific version of Chromium that you are targeting. Pay careful attention to have matching versions. Launch time depends on the complexity and size of the app. But generally, the VSNapshot made app launch time faster by more than 30%.
Let's talk about scrolling performance. On TV devices, media-type apps like the Media Player need to scroll through many great items. Therefore, ensuring smooth scrolling is critical to provide a native app quality experience to users. So, how did we improve from left to right? To handle very long list items, we created the Virtual List component. Virtualized techniques are now in common, and there are many great virtualized list components out there.
Comments