Frontend School

Performant Log Viewer with Virtualized List

Machine Coding
medium

Performant Log Viewer with Virtualized List

Medium
React
TypeScript
Virtualization
Performance
Frontend

Overview

Modern web applications often deal with displaying large datasets, such as log streams, chat histories, or data tables. Rendering millions of elements directly into the DOM can severely degrade performance, leading to slow load times and janky scrolling experiences. This problem focuses on building a performant UI component that efficiently renders a very long list of log entries, showcasing your ability to tackle performance challenges with virtualization techniques.

What you need to do / Task

Your task is to implement a LogViewer React component that efficiently displays a potentially millions of log entries. The component must use virtualization to only render the visible portion of the list, plus a small buffer, to maintain high performance.

  1. Implement Virtualized List: Create a scrollable container for log entries. Only a subset of log entries (those currently visible in the viewport plus a small buffer above and below) should be present in the DOM at any given time.
  2. Handle Variable Row Heights: Log entries will have varying message lengths, leading to different row heights. Your virtualization logic must correctly account for these variable heights to ensure accurate scrolling and element positioning.
  3. Scroll Controls: Add two buttons: "Scroll to Top" and "Scroll to Bottom". These buttons should programmatically scroll the virtualized list to the respective ends.

UI/UX expectations

  • The LogViewer component should render within a fixed-height container (e.g., 500px).
  • Each log entry should display its id and message.
  • Scrolling should be smooth and responsive, even with thousands or millions of underlying data items.
  • The "Scroll to Top" and "Scroll to Bottom" buttons should be clearly visible and functional, immediately navigating the user to the respective end of the list.

Acceptance criteria

  • The LogViewer component successfully renders and displays a large list of log entries without freezing the browser or exhibiting significant performance degradation.
  • Upon inspection (e.g., using browser developer tools), only a limited number of log entry DOM elements are present, corresponding to the visible viewport and buffer.
  • As the user scrolls, new log entries appear smoothly, and out-of-view entries are efficiently removed from the DOM.
  • The "Scroll to Top" and "Scroll to Bottom" buttons correctly navigate the scrollable area to the first and last log entry, respectively.
  • The virtualization logic correctly handles log entries with variable heights, preventing visual glitches or jumpiness during scrolling.

Constraints

Constraints & assumptions

  • The application will run in a modern web browser environment.
  • The total number of log entries can range from a few thousands to several millions.
  • Each log entry will be an object with an id: number and message: string. The message length can vary significantly, leading to variable row heights.
  • The container for the virtualized list will have a fixed height (e.g., 500px). Its width can be fluid.
  • You are expected to implement the virtualization logic from scratch; using an existing third-party virtualization library (e.g., react-virtualized, react-window) is not allowed for the core virtualization task, but utility libraries are fine.
  • Focus on React with TypeScript.

Out of scope

  • Loading more data (e.g., infinite scroll beyond the initially provided dataset).
  • Filtering, sorting, or searching capabilities for log entries.
  • Editing or interacting with individual log entries beyond basic display.
  • Accessibility enhancements beyond standard semantic HTML (unless explicitly part of UI/UX).

What interviewers evaluate

  • Core Virtualization Logic: Correctness and efficiency of the algorithm for rendering only visible elements.
  • Performance & Responsiveness: The application remains fast and responsive during scrolling, even with large datasets.
  • Variable Height Handling: Robustness in managing dynamic row heights without visual artifacts.
  • Code Quality: Readability, maintainability, modularity, and appropriate use of React hooks and TypeScript types.
  • Problem-Solving: Ability to identify and address performance bottlenecks in UI rendering.

Loading editor...