Crafting a better, faster code view
Blog post from GitHub
GitHub has developed a new code view designed to enhance the code reading experience by introducing features such as a file tree, symbol navigation, and code search integration, all while maintaining speed and usability for millions of users. The development process involved overcoming significant performance challenges associated with rendering large files, which were initially addressed through typical React optimization techniques but ultimately required the implementation of virtualization. Virtualization significantly improved load times by only rendering lines visible in the viewport, but it initially compromised the browser's native find-in-file functionality. To resolve this, GitHub introduced a dual-layer solution: a hidden textarea containing the full text for accessibility and findability, and a visible, virtualized syntax-highlighted overlay. This approach preserves both performance gains and user functionality, enhancing the code reading experience without turning GitHub into an IDE. The solution also involved innovating in syntax highlighting and HTML generation to further optimize performance, making the new code view faster and more feature-rich than its predecessor.