Frontend School

High-Performance Virtualized Log Viewer

Machine Coding
hard

High-Performance Virtualized Log Viewer

Hard
Virtualized List
Performance
React
Frontend
Dynamic Height

Overview

Modern applications generate vast amounts of log data, crucial for debugging and monitoring. Displaying these logs efficiently in a user interface, especially when dealing with hundreds of thousands or even millions of entries, presents a significant performance challenge. Traditional rendering approaches would quickly overwhelm the browser, leading to sluggish UIs and poor user experience.

This problem requires you to build a high-performance log viewer component capable of rendering a massive dataset of log entries. The core challenge lies in implementing a virtualized list that efficiently displays only the visible portion of the logs, while also accommodating dynamic row heights for varying log message lengths, ensuring a smooth and responsive user experience.

What you need to do / Task

Your primary task is to implement a VirtualizedLogViewer React component with the following features:

  1. Virtualized Rendering: Display a large list of LogEntry items using virtualization. Only a small subset of log entries should be rendered in the DOM at any given time, corresponding to what is currently visible in the scrollable area, plus a small buffer.
  2. Dynamic Row Heights: Each LogEntry can have a variable height due to multi-line log messages. Your virtualization solution must correctly account for these dynamic heights to ensure accurate scrolling and positioning of items.
  3. Scroll to Top/Bottom: Implement two buttons, "Scroll to Top" and "Scroll to Bottom", that allow the user to instantly navigate to the beginning or end of the log list.
  4. Performance: The component must remain highly performant and responsive even when dealing with 100,000+ log entries, demonstrating smooth scrolling without noticeable lag or jank.

UI/UX expectations

  • The VirtualizedLogViewer should occupy a defined height and width, providing a scrollable container for the log entries.
  • Each log entry should display its timestamp, level, and message.
  • Log messages can wrap to multiple lines, contributing to dynamic row heights.
  • Two distinct buttons, "Scroll to Top" and "Scroll to Bottom", should be present outside the scrollable log area, clearly visible and functional.
  • The UI should be clean and functional, prioritizing performance and usability over elaborate styling.

Acceptance criteria

  • The component renders a list of mock log entries.
  • Scrolling through 100,000+ items is fluid and responsive, without significant performance degradation.
  • Only a limited number of log items (e.g., 20-50, depending on viewport size) are present in the DOM at any given time, even with a massive dataset.
  • Log entries with varying message lengths are displayed correctly, and their positions are accurately maintained during scrolling.
  • The "Scroll to Top" button navigates the view to the first log entry.
  • The "Scroll to Bottom" button navigates the view to the last log entry.
  • No excessive re-renders or layout thrashing observed during scrolling (e.g., using React DevTools profiler).

Constraints

Constraints & assumptions

  • Data Size: The component will be tested with datasets ranging from 100,000 to 1,000,000 LogEntry objects.
  • Environment: React application running in a modern web browser.
  • Log Entry Structure: Each log entry will have id: string, timestamp: string, level: 'INFO' | 'WARN' | 'ERROR', and message: string.
  • Message Length: message strings can vary significantly in length, from short single-line messages to long multi-line paragraphs.
  • Fixed Item Width: Assume the width of the log viewer and individual log items is fixed, and only height varies.
  • No External Libraries: Do not use third-party virtualization libraries (e.g., react-window, react-virtualized). The solution must be implemented from scratch.

Out of scope

  • Filtering, searching, or sorting log entries.
  • Real-time streaming or infinite loading of new log data.
  • Complex styling or theming beyond basic layout.
  • Accessibility features beyond standard semantic HTML (e.g., keyboard navigation for individual log items).

What interviewers evaluate

  • Core Virtualization Logic: Correctness and efficiency of the custom virtualization implementation, especially for dynamic heights.
  • Performance Optimization: Strategies employed to ensure smooth scrolling and minimize DOM manipulation for large datasets.
  • Code Quality & Architecture: Clarity, maintainability, and extensibility of the React component design.
  • Problem Solving: Ability to tackle complex UI performance challenges and identify appropriate solutions.

Loading editor...