Book Deep-Read · Software Engineering at Google · Chapter 20
Software Engineering at Google · Ch 20 · Static Analysis · Caitlin Sadowski · 2020
Word processors have spell-check: before you hand in the essay, a red squiggle already sits under the typo. Code has the same thing, called "static analysis" — before the program ever runs, a machine reads the code and points out likely mistakes. This chapter is about how Google got tens of thousands of engineers to actually read those squiggles instead of ignoring all of them.
You'd assume the smarter the checker and the more it catches, the better. Google found the opposite: once a tool is wrong one or two times out of ten, people learn to dismiss it without looking — and the few real warnings get thrown out with the rest. What decides whether a checker lives or dies is not how much it catches, but how rarely it cries wolf.
Picture a smoke alarm that goes off every time someone cooks. By week three, the residents pull the battery — and on the day of a real fire, it stays silent. Early code checkers were like that: piles of reports, many of them mistaken or written so nobody understood them, usually delivered as a list of thousands with no clue who should fix what, or why now.
The result: the system looks at more than fifty thousand changes a day, fewer than one in twenty of its notes are seen as "crying wolf", and authors accept a machine-made fix about three thousand times a day. The honest cost: to avoid crying wolf, it simply stays quiet about many "maybe, can't be sure" cases — it knowingly lets some real problems through in exchange for being listened to.
A code checker isn't better because it catches more. It should say a few accurate things, right after you've made a change and while a colleague is looking, and hand you the fix — only a trusted tool gets heard.
Want the definition of an "effective false positive", Tricorder's four admission criteria and feedback loop, why personal customization was removed, why the compiler never warns, and how to choose between the IDE, code review, presubmit and the compiler? → Switch to Deep read
You'd think the hard part of static analysis is "is the analysis powerful enough?" This chapter says the real bottleneck is whether people are willing to look: by pushing user-perceived false positives below 10%, reporting only on the current change, putting results inside code review, and attaching one-click fixes, Google turned static analysis from "reports nobody reads" into infrastructure whose suggestions are accepted thousands of times a day.
The fifth chapter of Part IV, "Tools", right after Ch19 Critique: that chapter showed the review tool inlining analysis results into the diff; this one explains where those results come from. It also serves Ch15 "Deprecation" and Ch22 "Large-Scale Changes" by stopping people from sliding back to an old API mid-migration. Real-world counterparts: Error Prone, clang-tidy, ESLint, SonarQube, GitHub code scanning.
Static analysis can catch a class of bugs before code is checked in: constant expressions that overflow, tests that never run, invalid logging format strings that would crash at runtime. At Google it does more: it codifies best practices as rules, keeps code current with newer APIs, and prevents backsliding while old systems are deprecated.
The difficulty: research spent decades on "stronger analyses", while making tools scalable and usable is a relatively recent focus — and Google's early attempts to integrate static analysis into the workflow failed. Left unsolved, reports go unread, real findings drown in noise, and engineers route around the tool. So the chapter's question is: on a codebase of billions of lines, what kind of static analysis do engineers actually accept?
With billions of lines, full-codebase analysis on every change is out of the question. Tricorder's analyses are shardable and incremental: they analyze only the files affected by the pending change and usually show results only for edited files or lines. Analyzers are solicited from across the company, and results go straight to the relevant engineers instead of through a central team.
"New code only" is also a usability decision. "Fixing" a warning in old code that runs fine in production has unclear benefit and real risk: the book's example is silencing a dead-code warning by adding a call to it, so that never-tested code suddenly starts running. So the focus is newly introduced warnings; existing issues are worth raising only if they are especially important (security issues, significant bugs). A bonus: the person seeing the warning is the one with the most context on that code.
Research traditionally chased fewer false negatives; in practice, a low false-positive rate is what makes engineers willing to use a tool — who wants to wade through hundreds of bogus reports to find a few real ones? The chapter's central concept is the effective false positive: if a developer sees a result and takes no positive action, it counts as one.
contains on a Java hash table, which is equivalent to containsValue, when the developer most likely meant containsKey; even if they really meant the value, containsValue is clearer.This moves the metric from "is the rule logically right?" to "did a human act on it?", which pulls message wording, importance and timing into the measurement. A footnote leaves one exception: for security analyses that find critical problems, reviewers may tolerate a much higher false-positive rate.
Tricorder is Google's static analysis platform; what set it apart from the earlier failed attempts was a relentless focus on delivering only valuable results. It uses a microservices architecture: Tricorder sends analyze requests with change metadata to analysis servers; the servers read the change's file versions through a FUSE-based filesystem and can use cached build inputs and outputs; each analyzer's output goes to a storage layer, and the latest results per category appear in Critique's diff as gray comment boxes.
Any engineer can write an analyzer or contribute a check to an existing one. New checks must meet four criteria:
The numbers: more than 50,000 code review changes analyzed per day, often several analyses per second; 30+ languages; 100+ analyzers, most contributed from outside the Tricorder team, seven of which are themselves plug-in systems with hundreds of further checks; overall effective false-positive rate just below 5%.
The integrated tools vary widely. Error Prone (Java) and clang-tidy (C++) extend the compiler to find AST antipatterns. The book's example: a hash of a long field written (int)(f ^ (f >>> 32)) — if f becomes an int, shifting by 32 is a no-op, f is XORed with itself to zero, and it still compiles. Turning that check into an Error Prone compiler error fixed 31 occurrences in the codebase. Others span files: IfThisThenThat requires two files' marked regions to change together; Chrome's Finch analyzer checks A/B experiment configs; a binary-size checker warns when a change grows the binary significantly. Note that almost all analyzers are intraprocedural, looking only inside one function — interprocedural analysis is feasible but needs extra infrastructure investment.
"If you don't measure this, you can't fix problems." Every result has a Not useful button that lets the user file a bug straight to the analyzer author, prefilled with the result's details; reviewers can click Please fix to ask the author to address it. The Tricorder team watches analyzers whose Not useful rate is high relative to Please fix clicks, and disables them if they don't improve. Before these channels existed, many developers simply ignored results they didn't understand.
Sometimes the fix is just rewording a message. Error Prone once shipped a check flagging too many arguments passed to a printf-like Guava function that accepts only %s. The team got weekly Not useful reports saying "the placeholders and arguments match" — because users were passing specifiers other than %s. Once the message said outright that the function accepts only %s, the reports stopped.
Suggested fixes follow the same logic: anything that can be fixed automatically should be, and a fix doubles as documentation. Fixes apply with one click in Critique or across a whole change from the command line. Style issues belong to formatters; human reviewers shouldn't spend time on formatting. The numbers: reviewers click Please fix thousands of times a day, authors apply automated fixes about 3,000 times a day, and Not useful gets about 250 clicks a day.
Only after building trust with high-confidence results did Google add optional analyzers for specific projects. The Proto Best Practices analyzer, for instance, flags protocol buffer changes that could break the data format — which matters only if serialized data is stored somewhere (say, in logs), so projects without stored data needn't enable it. Some optional analyzers improved through feedback, gained a big user base, and graduated to on-by-default.
The key insight: customization at the project level, not the user level. Project-level settings give the whole team a consistent view and prevent one developer from fixing an issue while another introduces it. Early Critique let each user pick a confidence level and suppress specific analyses; the team removed all of that and immediately got complaints about annoying results. Instead of restoring the settings, they asked why — and found hidden bugs: the C++ linter was also running on Objective-C files and producing useless results; the HTML linter had an extremely high false-positive rate with little signal and was usually suppressed anyway, so it was disabled. Conclusion: user customization hides bugs and suppresses feedback.
Code review is the sweet spot: nearly all code is reviewed before commit, authors are already in a "change" mindset and can fix things without much disruption; after mailing a change they're waiting on reviewers anyway, so analyses can take minutes; reviewers add peer pressure; and analyzers catch common issues so reviewers don't have to, which helps review itself scale. Analyses also see the whole change in context — a dead-code analysis would misfire on half-written code where a function exists before its call sites.
Presubmits close the "warnings can be ignored" gap by blocking the commit. Built-in checks are simple — the description must not say DO NOT SUBMIT, code files must come with their tests, formatting must be right; teams can require zero Tricorder issues in a category or write custom presubmits so new projects hold a higher bar than legacy ones. The cost: they can get in the way of large-scale changes, so some team presubmits are skipped for changes with CLEANUP= in the description.
The compiler is the hardest slot: a broken build is a warning nobody can ignore. Compiler checks must be fast and meet three criteria: actionable and easy to fix (ideally with a mechanically applicable fix), zero effective false positives (never stop the build for correct code), and correctness only, not style or best practices.
A new check requires cleaning up every existing instance in the codebase first, so the compiler's evolution doesn't break existing projects. That means the check's value must justify fixing every old instance. Google can run compilers over the whole codebase in parallel on a cluster as a MapReduce; the check must then produce fixes so the cleanup can be automated.
One more hard rule: never issue compiler warnings. Google has found repeatedly that developers ignore them, so a check is either an error or absent from compiler output; since compiler flags are shared across the codebase, the decision is global. The most-used languages follow this, though not every language does. Go takes it to the extreme: unused variables and imports, mere warnings elsewhere, are errors in Go.
Finally, the IDE: analyses typically must finish within 1 second, ideally 100 ms, and behave identically across multiple IDEs (Google doesn't mandate one), so it's messier than plugging into review. And one exception: security teams and people planning cleanups want whole-codebase results while browsing code.
One criterion decides the slot: how fast, how precise, and how correctness-critical the check is.
Table 1 · Integration points for static analysis
| Slot | Latency budget | Can be ignored? | Fits | Cost |
|---|---|---|---|---|
| IDE | < 1 s, ideally < 100 ms | Yes | Fast, local checks | Hard to keep consistent across IDEs; misfires on half-written code |
| Code review | Minutes | Yes, but you must convince the reviewer | Most checks (effective FPs < 10%) | Can be ignored; arrives after editing |
| Presubmit | At mail-out and at commit | No (blocks commit) | Formatting, tests, team mandates | Custom team checks can hamper large-scale changes |
| Compiler ERROR | Must not slow the build | No (blocks build) | Mechanical, zero-FP correctness checks | Whole codebase must be cleaned first |
| Code browsing | Offline | — | Security audits, cleanup planning | Digs up old code; fixing it is risky |
Table 2 · Google's trade-offs
| Decision | Gave up | Gained | Honest cost |
|---|---|---|---|
| Precision first | Chasing low false negatives | User trust; results get read | Knowingly misses some real issues |
| New code only | Whole-codebase backlog lists | The fixer has context; stable old code untouched | Old issues linger unless security-grade |
| Per-project customization | Personal toggles and confidence levels | Consistent team view; problems surface instead of being muted | Individuals can't silence a check they dislike |
| No compiler warnings | Gentle warnings | Either it blocks or it stays quiet | A new error means fixing the whole codebase first |
| Mostly intraprocedural | Cross-function analysis | Fast, shardable, maintainable | Misses bugs that propagate across functions |
When you add a linter, SAST tool or AI review bot to a repo, this chapter gives three yardsticks: are effective false positives measured (a "not useful" button, per-analyzer stats)? does the result appear right after the author made the change? can it be fixed in one click? When a review asks "should this rule block merges?", apply the compiler's three criteria — mechanical, zero false positives, correctness-related. Block only if all three hold; otherwise keep it as a review suggestion.
Industry evidence · publicly verifiable
error:, not a warning — exactly the chapter's "in the compiler means an error" slot. google/error-prone · README ↗① The bottleneck isn't analysis technique but whether engineers will look; Google's early integration attempts failed.
② Scale: analyze only files affected by the change, report only on edited lines; solicit analyzers company-wide and route results directly to the relevant engineers.
③ Effective false positive = no positive action after seeing it; confusing or unimportant both count. The metric moves from "is the rule right?" to "did a human act?"
④ Tricorder's four criteria: understandable, actionable and easy to fix, under 10% effective false positives, significant impact; overall rate just below 5%.
⑤ The feedback loop is a product feature: Not useful goes straight to authors; a high rate relative to Please fix means fix it or disable it; rewording a message can erase "false positives".
⑥ Automate every fix you can: about 3,000 one-click fixes a day; style belongs to formatters, not reviewers.
⑦ Customize per project only: personal toggles hide bugs and suppress feedback.
⑧ Layer the integration points: review is the main venue; presubmit blocks commits; the compiler accepts only mechanical, zero-false-positive correctness checks, cleaned up first, and never warns.
⑨ Limits: mostly intraprocedural, so cross-function bugs slip through; the approach leans heavily on a monorepo and a unified toolchain.