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