Benefits of stacked diffs in code review

Greg Foster
Greg Foster
Graphite software engineer

Stacked diffs, also known as stacked changes or pull requests (PRs), represent a series of dependent code changes where each PR builds off of its parent. This methodology is particularly beneficial in the code review process for several reasons, primarily because it allows large engineering tasks to be divided into small, incremental, and manageable pieces that can be tested, reviewed, and merged independently​​.

By organizing complex features into smaller units, stacked diffs encourage incremental development. This method not only expedites the landing of changes but also aligns with agile principles by allowing continuous integration and delivery. Developers can focus on one aspect of the feature at a time, ensuring that each piece is fully functional and tested before moving on to the next​​.

Stacked diffs create parallel workstreams, where each stack represents a specific piece of functionality. This clarity simplifies development and review processes, as the structure of the work is more straightforward and compartmentalized. It allows developers to remain productive by working on subsequent PRs while awaiting review on others, effectively reducing idle time and improving overall project momentum​​.

Smaller, more focused changes are easier to understand and review, leading to quicker and more efficient code review cycles. This approach limits the cognitive load on reviewers, who can provide more accurate and helpful feedback. Moreover, it simplifies the process of identifying where issues might have been introduced, making it easier to bisect and, if necessary, roll back changes without affecting the entire codebase​​.

Stacked diffs facilitate tighter collaboration among development team members. They allow developers to work together on shared stacks, which can streamline the process of resolving merge conflicts. Because each change is isolated, developers can address issues in one part of the stack without impacting others, leading to more efficient parallel development​​.

To maximize the benefits of stacked diffs, it's essential to create self-contained, atomic PRs, ideally between 50 to 100 lines long. Each stack should focus on a single cohesive change or feature to prevent mixing unrelated changes. Additionally, the order of the stacks should be carefully managed to ensure that dependencies are merged in the correct sequence, maintaining the integrity and functionality of the codebase​​.

By adopting stacked diffs, developers can enjoy a more organized, collaborative, and efficient code review process. This technique has been employed by major tech companies with large-scale codebases and numerous engineers, reflecting its effectiveness in maintaining code health and streamlining development workflows.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Get started

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2