Crafting a better, faster code view

The new GitHub Code View brings users many new features to improve the code reading and exploration experiences, and we overcame a number of unique technical hurdles in order to deliver those features without compromising performance.

Joshua Brown
15 min readadvanced
--
View Original

Overview

The article discusses the development of a new code view on GitHub aimed at enhancing the code reading experience for developers. It highlights the challenges faced in performance optimization and the innovative solutions implemented, such as virtualization and a dual-layer structure for code representation.

What You'll Learn

1

How to implement virtualization for improved performance in web applications

2

Why optimizing DOM interactions is crucial for user experience

3

How to enhance accessibility in web applications using native browser features

Prerequisites & Requirements

  • Understanding of web performance metrics like LCP and TTI
  • Familiarity with React and its optimization techniques(optional)

Key Questions Answered

What performance issues arise when rendering large code files?
Performance issues such as increased Largest Contentful Paint (LCP) and Time to Interactive (TTI) occur when files exceed 500 lines, becoming significantly noticeable at around 2,000 lines. This leads to sluggish interactions, highlighting the need for optimization in code viewing experiences.
How does virtualization improve the code reading experience?
Virtualization optimizes performance by only rendering the lines of code visible in the viewport, significantly reducing initial render times from 27 seconds to under one second, even for large files. This allows for a smoother scrolling experience without sacrificing functionality.
What is the role of the textarea in the new code view?
The textarea contains the entire text of the raw file, making it accessible, keyboard-navigable, and findable, while remaining invisible to users. This allows for native browser functionalities like Ctrl+F to work seamlessly, enhancing user experience.
What challenges did the team face with the find-in-file functionality?
The initial virtualization implementation limited the find-in-file functionality to only visible lines, breaking user expectations. The team had to create a custom solution to ensure users could search the entire file, ultimately deciding to leverage the native browser find functionality for better accessibility.

Key Statistics & Figures

Initial render time for large files
27 seconds
This was the time taken to render an 18,000-line CODEOWNERS file without optimizations.
Improved initial render time with virtualization
under 1 second
Virtualization reduced the initial render time significantly, even for large files.
User abandonment rate after 3 seconds of loading
more than 50%
This statistic highlights the importance of fast loading times for user retention.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Key Actionable Insights

1
Implement virtualization techniques in your web applications to enhance performance, especially when dealing with large datasets.
Virtualization allows you to render only what is necessary, significantly improving load times and user interactions, which is crucial for maintaining user engagement.
2
Utilize native browser features for accessibility to improve user experience for all users, including those using assistive technologies.
By leveraging built-in functionalities like Ctrl+F, you can create a more intuitive interface that aligns with user expectations and improves overall accessibility.
3
Focus on optimizing DOM interactions to reduce performance bottlenecks in your applications.
Understanding how DOM nodes affect rendering times can help you implement strategies to minimize delays, ultimately leading to a smoother user experience.

Common Pitfalls

1
Over-optimizing early in the development process can lead to unnecessary complexity and hinder progress.
The article emphasizes the importance of building features in a straightforward manner before applying optimizations, which can complicate the development process and delay delivery.
2
Neglecting accessibility features can alienate users who rely on assistive technologies.
The initial implementation of the new code view lacked accessibility, which prompted the team to rethink their approach and ensure that all users could effectively navigate and interact with the code.

Related Concepts

Web Performance Optimization Techniques
Accessibility Best Practices In Web Development
React Optimization Strategies