Frontend School

Performance-optimized Virtualized Log Viewer

Machine Coding
medium

Performance-optimized Virtualized Log Viewer

Medium
React
Virtualized List
Performance
UI
TypeScript

Overview

In modern applications, displaying large datasets efficiently is crucial for a smooth user experience. Imagine a system that generates millions of log entries daily. Directly rendering all these entries would quickly overwhelm the browser, leading to sluggish performance and potential crashes. This problem challenges you to implement a performant solution for viewing such extensive lists using the virtualization technique, ensuring a responsive and efficient UI.

What you need to do / Task

  1. Create a VirtualizedList component: This component will be responsible for rendering a subset of items visible within its viewport, rather than all items in the dataset.
  2. Display Log Entries: The component should accept an array of LogEntry objects and render them. Each entry should display its id, timestamp, and message.
  3. Implement Scrolling Logic: As the user scrolls, the VirtualizedList must dynamically calculate which items are currently visible and update the rendered content accordingly, ensuring a seamless scrolling experience.
  4. Position Visible Items: Correctly position the visible items within the scrollable container to simulate the presence of all items, without actually rendering them.

UI/UX expectations

  • The log viewer should occupy a fixed height and width on the screen, acting as a scrollable container.
  • Each log entry should be clearly distinguishable, perhaps with a border or background.
  • Scrolling through tens of thousands of log entries should feel smooth, without noticeable lag, flickering, or empty spaces.
  • The scrollbar should accurately reflect the total number of items, even though most are not rendered.

Acceptance criteria

  • The VirtualizedList component successfully renders only a small, fixed number of LogEntry elements in the DOM at any given time, regardless of the total dataset size.
  • Scrolling through the list is fluid and performant, without UI jank or delays.
  • All log entries (from the beginning to the end of the dataset) are accessible by scrolling.
  • The scrollbar accurately reflects the total height of all items, not just the rendered ones.
  • No external virtualization libraries are used; the core virtualization logic is implemented from scratch.

Constraints

Constraints & assumptions

  • Dataset Size: You will be working with a mock dataset of ~100,000 log entries.
  • Fixed Row Height: Assume all log entries have a consistent, fixed height (e.g., 40px). This simplifies the virtualization calculations.
  • Environment: React with TypeScript.
  • Time Budget: This problem is designed to be completed within approximately 45 minutes.
  • No External Libraries: Do not use third-party virtualization libraries (e.g., react-window, react-virtualized). The core logic must be implemented by you.

Out of scope

  • Dynamic row heights.
  • Advanced features like searching, filtering, or sorting.
  • Two-dimensional virtualization (grid view).
  • Infinite scrolling (loading more data on scroll).
  • Accessibility enhancements beyond basic semantic elements.

What interviewers evaluate

  • Core Virtualization Logic: Correctness and efficiency of the algorithm for determining and rendering visible items.
  • Performance: The application's responsiveness and DOM footprint under heavy data loads.
  • Code Quality: Readability, maintainability, and proper use of React patterns (hooks, memoization where appropriate).
  • Problem-Solving: Ability to break down the problem, identify key challenges, and implement a robust solution.

Loading editor...