Key Moments

Mondrian Code Review On The Web

Google TalksGoogle Talks
Education6 min read56 min video
Aug 22, 2012|19,697 views|98|5
Save to Pod
TL;DR

Google's Mondrian system revolutionizes code review by moving it online, improving collaboration and efficiency, but its reliance on Perforce can still cause performance bottlenecks.

Key Insights

1

Code review is presented as a vital, almost mandatory, part of the software development process, akin to pair programming in principle.

2

The traditional code review process, especially in open source, relies heavily on email for sending patches (context diffs or unified diffs) and subsequent critique.

3

Mondrian's web-based system addresses limitations of command-line and email-based reviews, such as issues with remote access (VPNs), out-of-sync comments due to code changes, and workflow management.

4

Key features of Mondrian include snapshotting every version of code under review, side-by-side diffs with inline comments, and a centralized repository for all review-related messages.

5

Mondrian integrates with email, automatically sending notifications and allowing replies to be logged back into the system, making it accessible to users who prefer email-based workflows.

6

Despite its improvements, Mondrian's performance is often bottlenecked by Google's internal Perforce system, which is not inherently scalable or distributed.

The fundamental importance of code review

Guido van Rossum begins by emphasizing that code review is a critical, often voluntary, component of the software development lifecycle, comparable in its principled application to pair programming. The core idea is that two pairs of eyes are better than one, catching more bugs and improving code quality. This process, ideally conducted in a non-threatening environment, fosters dialogue between developers. Beyond bug detection, code review is crucial for enforcing coding standards and style guides, ensuring code uniformity that facilitates readability and maintenance over long periods. It's also a powerful tool for mentorship, allowing senior developers to guide junior developers, imparting knowledge of codebase conventions and invariants, and building trust. Van Rossum posits code review as a strong alternative to pair programming, especially in environments with frequent interruptions.

Traditional code review workflows and their limitations

In open-source settings, code review often involves developers emailing patches (context or unified diffs) to a reviewer. The reviewer critiques the code line-by-line, and the author iteratively refines the changes, resending patches until the reviewer approves. The reviewer typically has the final say on committing the code to the repository. While effective for knowledge transfer and identifying good junior developers, this email-centric approach has significant drawbacks. It struggles with remote access, especially over VPNs, making diff tools difficult to use. Comments made on specific lines can quickly become outdated as the author incorporates changes from multiple reviewers or makes other modifications, leading to confusing email trails that are hard to follow months later. Furthermore, managing review requests within overflowing inboxes can lead to lost messages and the need for constant pinging between author and reviewer, highlighting a lack of workflow management.

Introducing Mondrian: A web-based solution

Neil Noritz's initial suggestion for a web-based code review system sparked the development of Mondrian, designed to overcome the limitations of existing command-line and email-based methods. The primary goal was to create a more accessible and efficient review process, particularly for developers working remotely or at odd hours. Key features planned from the outset included snapshotting every version of code under review to maintain a complete history, providing side-by-side diff views for clearer comparison, and incorporating inline comments directly on code lines. The system was also envisioned as a central repository for all review-related discussions, ensuring that all communication for a specific change list was easily retrievable. Crucially, Mondrian was designed for gradual adoption, with strong email integration to accommodate users who preferred or relied on email communication.

Core features and user interface of Mondrian

Mondrian's user interface is centered around a personal dashboard that displays different categories of code changes: those awaiting the user's review and those submitted by the user awaiting review. Changes that have been submitted but not yet reviewed are marked yellow, turning red if neglected for four weeks. Hovering over usernames can reveal profile pictures, and hovering over change lists provides summary details. The system supports reviewing changes submitted by others or one's own pending changes that are not yet ready for review. A notable feature is the ability to view someone else's dashboard, which can be helpful in customer support scenarios. Mondrian allows for reviewing changes assigned to groups, not just individuals, facilitating team-based review processes. The interface also allows navigation between multiple files within a change list and provides keyboard shortcuts for efficiency.

Advanced review functionalities: Diffs and comments

A significant aspect of Mondrian is its advanced diffing capabilities. Users can view inline diffs or full side-by-side diffs of entire files. The system offers inline comments, allowing reviewers to click on any line of code and submit a review directly associated with that line. These comments are initially saved as drafts and can be published later. The system stores a history of all snapshots taken during the review process, identifiable by MD5 checksums, though sometimes different versions share the same checksum if no changes occurred. Reviewers can compare any two snapshots and utilize options to ignore whitespace differences. When comments are published, they are compiled into an email with hyperlinks, directing the author back to the specific location within Mondrian for response. The system also highlights subtle changes within a line, differentiating between changed text and unchanged surrounding text.

Technical architecture and backend integration

Mondrian is built using Python and Django templates, but notably, it doesn't rely on a traditional relational database. Instead, it utilizes Google's internal Bigtable service for data storage and employs a Python-based multi-threaded web server, leveraging the WSGI standard. The system interacts heavily with Google's Perforce (P4) version control system through a wrapper script that adds custom functionality, including code review support. Perforce is used for managing code changes and metadata, with Mondrian storing snapshots of code and associated metadata. The system also integrates with NFS for accessing workspaces and, when necessary, uses SSH to access local workspaces on user machines, though this is less automated. For users where neither NFS nor SSH is feasible, an option to upload context or unified diffs via email remains available.

Email integration and workflow management

Recognizing that a complete switch to a web interface would be impractical, Mondrian was designed with robust email integration. When a comment is added or updated in Mondrian, an email notification is sent to all involved parties. Replies to these emails are automatically parsed and logged back into Mondrian, preserving the conversation history. This dual approach allows users to interact with the system either through the web interface or via email, catering to different user preferences and workflow needs. The mail server scans incoming emails for change list numbers, associating comments with the correct change list and snapshot in the database. A critical function of the email processing is maintaining reviewers' to-do lists, as Perforce itself does not track what a developer needs to review.

Performance considerations and future development

While Mondrian itself is generally efficient, its performance is often dictated by the underlying Perforce system, which is a known bottleneck due to its limitations in scalability and distribution. Large files or extensive diffing operations can lead to significant delays. Generating the dashboard HTML, which crams a lot of information into a small space with interactive elements, can also be computationally intensive. Despite these challenges, the system handles a large volume of daily logins and weekly users, with most performance issues being attributed to waiting for Perforce. The core web and mail servers, running on a single machine, typically operate below 50% CPU load, demonstrating the efficiency of the application logic itself. All data, including code snapshots and review comments, is stored permanently for auditing and historical purposes, making Mondrian akin to a revision control system for pending changes.

Common Questions

Code review is a process where one developer writes code and another reviews it to identify potential improvements or bugs. It's crucial for catching errors early, ensuring code quality and uniformity, and facilitating knowledge transfer between developers.

Topics

Mentioned in this video

More from GoogleTalksArchive

View all 88 summaries

Ask anything from this episode.

Save it, chat with it, and connect it to Claude or ChatGPT. Get cited answers from the actual content — and build your own knowledge base of every podcast and video you care about.

Get Started Free