Robert Sesek | a8ee4a9 | 2023-07-13 23:04:30 | [diff] [blame] | 1 | # Tips for productive Chromium code reviews |
| 2 | |
| 3 | This page is meant to help both CL authors and reviewers have a more productive, |
| 4 | efficient, and mutually beneficial code review. **None of these tips represent |
| 5 | formal policy**, but following this guidance should help you get your changes |
| 6 | reviewed and landed faster. |
| 7 | |
| 8 | Please also read [Respectful Changes](cl_respect.md) and [Respectful Code |
| 9 | Reviews](cr_respect.md). |
| 10 | |
| 11 | ## Keep changes under 500 LoC |
| 12 | |
| 13 | Large changes take longer to review than smaller changes. Reviewers generally |
| 14 | need to familiarize themselves with the content of a CL after each round of |
| 15 | review, so the larger a CL is, the longer that process takes. Large CLs can also |
| 16 | fatigue a reviewer who goes line-by-line through a CL. Try to keep changes below |
| 17 | 500 lines of code – including tests. There is a balance here, though: 200 lines |
| 18 | of code (LoC) of production code with 600 LoC of tests might be fine, especially |
| 19 | if the test code follows a regular pattern. Conversely, 400 LoC of production |
| 20 | code with 200 LoC of test code may not provide enough coverage. |
| 21 | |
| 22 | If your CL is larger than that, seriously consider splitting it into smaller, |
| 23 | reviewable units. When splitting CLs, you should tag each CL with the same |
| 24 | tracking bug, so that the association is clear. You can also use the [relation |
| 25 | chain of dependent CLs](contributing.md#uploading-dependent-changes) to allow |
| 26 | the reviewer to see the progression before it is landed. |
| 27 | |
| 28 | ## Share context for the CL |
| 29 | |
| 30 | Providing context for the review is important for understanding the motivation |
| 31 | behind a change. The amount of context to share depends on the scale of the |
| 32 | change: a thorough CL description can be sufficient for a single, independent |
| 33 | patch. But sometimes it may be better to provide the context on a linked bug, |
| 34 | that e.g. documents the investigation that led to the proposed fix. If your |
| 35 | change is large, it is helpful to provide reviewers context for the series of |
| 36 | small-to-medium-sized CLs via a [design |
| 37 | doc](https://docs.google.com/document/d/14YBYKgk-uSfjfwpKFlp_omgUq5hwMVazy_M965s_1KA/edit#heading=h.7nki9mck5t64). |
| 38 | Highlight the problem that needs solving, an overall description of the proposed |
| 39 | solution, and any alternatives you considered. |
| 40 | |
| 41 | Your CL description should always document **what** you are changing and |
| 42 | **why**. CL descriptions are stored in the repository history, so they should be |
| 43 | written to stand the test of time. Ask yourself, "if another engineer, five |
| 44 | years from now, needed to understand why this CL landed based on the |
| 45 | description, would they be able to?" |
| 46 | |
| 47 | ## Guide the reviewer though complex CLs |
| 48 | |
| 49 | While the CL description goes on record, you can also leave comments on the CL |
| 50 | as well: If your CL contains one major change and a lot of fallout from that |
| 51 | change, you can point out where to start the review process. If you made a |
| 52 | design decision or trade-off that does not justify a comment in the source code, |
| 53 | you may still proactively leave a comment on the CL to inform the reviewer. |
| 54 | |
| 55 | ## Separate behavior changes from refactoring |
| 56 | |
| 57 | CLs should only effect one type of change. If you need to both refactor |
| 58 | something and change its behavior, it is best to do so over two separate CLs. |
| 59 | Refactoring generally should not change behavior. This benefits the reviewer, |
| 60 | who can more quickly evaluate a refactoring as a move-code-only change that does |
| 61 | not change behavior, and the author, who potentially avoids unnecessary reverts |
| 62 | and re-lands due to regressions caused by the behavior change. |
| 63 | |
| 64 | ## Encapsulate complexity, but don’t over-abstract |
| 65 | |
| 66 | One way to keep changes small is to build up composable units (functions, |
| 67 | classes, interfaces) that can be independently tested and reviewed. This helps |
| 68 | manage the overall change size, and it creates a natural progression for |
| 69 | reviewers to follow. However, do not over-design abstractions for an unknown |
| 70 | future. Allowing for extensibility when it’s not necessary, creating |
| 71 | abstractions where something concrete would suffice, or reaching for a design |
| 72 | pattern when something simpler would work equally well adds unnecessary |
| 73 | complexity to the codebase. The codebase is inherently mutable and additional |
| 74 | abstractions can be added _if and when_ they are needed. |
| 75 | |
Evan Stade | ce7bcd1 | 2025-03-31 16:46:46 | [diff] [blame] | 76 | ## Choosing the right reviewers |
| 77 | |
| 78 | For more on identifying the best contact, see |
| 79 | [finding somebody who knows how a piece of code works](finding_reviewer.md). |
| 80 | |
| 81 | ### Optimize for reducing timezone latency |
Robert Sesek | a8ee4a9 | 2023-07-13 23:04:30 | [diff] [blame] | 82 | |
| 83 | The Chromium project has contributors from around the world, and it is very |
| 84 | likely that you will not be in the same timezone as a reviewer. You should |
| 85 | expect a reviewer to be responsive, per the code review policy, but keep in mind |
| 86 | that there may be a significant timezone gap. Also see the advice about |
| 87 | [minimizing lag across |
| 88 | timezones](https://www.chromium.org/developers/contributing-code/minimizing-review-lag-across-time-zones/). |
| 89 | |
Evan Stade | ce7bcd1 | 2025-03-31 16:46:46 | [diff] [blame] | 90 | ### Get a full review from a single, main reviewer, before asking many OWNERs |
Robert Sesek | a8ee4a9 | 2023-07-13 23:04:30 | [diff] [blame] | 91 | |
| 92 | If your CL requires the approval from 3+ OWNERs, get a small number of main |
| 93 | reviewers (most commonly 1) to review the entire CL so that OWNERs don’t need to |
| 94 | deal with issues that anybody can detect. This is particularly useful if OWNERs |
| 95 | are in a different timezone. |
| 96 | |
Evan Stade | ce7bcd1 | 2025-03-31 16:46:46 | [diff] [blame] | 97 | ### Depend on more-specific owners |
Robert Sesek | a8ee4a9 | 2023-07-13 23:04:30 | [diff] [blame] | 98 | |
| 99 | Wherever possible, choose reviewers from the deepest OWNERS files adjacent to |
| 100 | the most significant aspects of your change. Once their review is complete, add |
| 101 | OWNERS from parent/less-specific directories for getting approvals for any API |
| 102 | change propagations. The parent-directory reviewers can typically defer to the |
| 103 | more-specific reviewers’ LGTM and simply stamp-approve the CL. |
| 104 | |
| 105 | Avoid adding multiple reviewers from the same OWNERS file to review a single |
| 106 | change. This makes it unclear what the responsibilities of each reviewer are. |
| 107 | Only one OWNERS LGTM is needed, so you only need to select one. You can use the |
| 108 | file revision history to see if one reviewer has been more recently active in |
| 109 | the area. |