Why measure churn instead of just checking it?
My post on prioritizing technical debt tells you to let high-churn files jump the queue and to "check git history" before trusting a gut feeling. I wrote that without measuring it. It's the standard advice, and so is its upgraded form, the hotspot: multiply how often a file changes by how complex it is, and the product tells you where the debt is charging interest. That's the idea Adam Tornhill built Your Code as a Crime Scene around.
If you price debt like a loan, as in the financial framing post, the interest has to show up somewhere you can count. Bug fixes are the most honest place. So the question I wanted answered is narrow: of the cheap signals you can compute in an afternoon, which one points at the files where bugs will actually get fixed next?
I didn't pick a winner in advance, though my guess going in was the hotspot.
What did I measure, and on what?
Two long-lived Python projects, full clones, on a Linux box: Sphinx (first commit 2007-07-23, 22,461 commits, head 035a07c) and pytest (first commit 2007-01-24, 17,934 commits, head 6ee1cb9). The design is a plain split in time:
- Population: every
.pyfile in the package (sphinx/orsrc/), tests excluded, at the last commit before the split date. For the main run that's 173 Sphinx files with 48,492 SLOC. - History window: the two years before the split. Here I count commits per file, lines added plus deleted, distinct authors, and past bug-fix commits.
- Snapshot: at the split commit, radon 6.0.1 gives the summed cyclomatic complexity and the SLOC of each file. Hotspot is history commits times snapshot complexity.
- Outcome window: the two years after the split, with renames followed by
git log -M. The outcome is bug-fix touches per file.
The main run splits on 2024-01-01, so history is 2022-2023 and the outcome is 2024-2025. I repeated it for split dates 2021, 2022 and 2023 on both repos, which makes 8 runs, each scoring nine orderings of the files. One run takes about 15 seconds. Why two repos and four windows? Because one run can tell you anything you want to hear.
The bug-fix rule is a regex on the commit message:
BUG = re.compile(r"\b(fix|fixes|fixed|fixing|bug|bugs|bugfix|regression|crash|crashes)\b"
r"|\b(close[sd]?|resolve[sd]?)\s+(gh-|#)\d+", re.I)
SWEEP = 10 # a "fix" touching more than 10 package files is a sweep, not a bug fix
The sweep rule came from looking at the data, and I'd rather say so. Without it, Sphinx's 2022-2023 window counted "Fix module docstring indentation" (177 files) and a string of "Fix TCH001"-style lint commits as bug fixes, and those alone swamped the outcome. In the main runs it removed 1 Sphinx commit and 3 pytest commits, including pytest's move to ruff (63 files).
Which signal ranks files best?
Here's the conventional scorecard for the main Sphinx run. Spearman's rho is between the signal and later bug-fix touches across all 173 files. "Top 10%" is the share of later bug-fix touches that land in the 17 files the signal ranks highest.
| Signal (Sphinx, history 2022-2023) | Spearman rho | Top 10% of files: share of later fixes | Top 10% of files: share of all code |
|---|---|---|---|
| Commit count (churn) | 0.526 | 37.0% | 42.0% |
| Hotspot (churn x complexity) | 0.504 | 39.4% | 47.5% |
| Number of authors | 0.497 | 37.9% | 41.9% |
| Cyclomatic complexity | 0.468 | 37.8% | 47.3% |
| Lines changed | 0.461 | 32.3% | 42.3% |
| Past bug-fix commits | 0.446 | 31.4% | 37.2% |
| File size (SLOC) | 0.416 | 39.4% | 48.4% |
Every signal works, by this measure. They all correlate positively and comfortably clear the 10% a random pick would catch. Across all 8 runs the rho values run from 0.42 to 0.84, and the hotspot had the highest rho in 4 of the 8. If you stopped at this table, you'd ship a hotspot dashboard and feel good about it.
The bootstrap intervals tell you not to read too much into the order, though. Churn's 95% interval is 0.41 to 0.63 and the hotspot's is 0.38 to 0.62. They overlap almost completely. And they should: the hotspot correlates with plain complexity at 0.983 on Sphinx, and complexity correlates with file size at 0.823. Multiplying churn by complexity mostly re-sorts files by how big they are.
So what's wrong with the last column?
Look at the right-hand column again. The 17 files the hotspot flags hold 47.5% of all the code, and they collect 39.4% of the later fixes. Per line, the files it points at are less likely to see a bug fix than the codebase average. That holds for every signal in the table on Sphinx.
Nobody reviews a file list. People review code, and code costs time per line. So I added a second score: read files in the signal's order until you've read 20% of all lines, and count what share of the next two years' bug-fix touches you passed through. Random order gives about 20%. A signal worth having beats that.
On the main Sphinx run, hotspot order finds 1.7%. Complexity and file size do the same 1.7%, because all three start with the same two files: sphinx/domains/cpp.py (6,513 SLOC, complexity 2,294, 70 commits in two years) and sphinx/domains/c.py (3,124 SLOC). Together they're 19.9% of the code. In the following two years they drew 49 and 42 commits, and one bug-fix touch each. They were busy being refactored, not being fixed. Is that a hotspot? By the formula, it's the hottest spot in the repo.
Then I tried the obvious correction. Divide churn by size, commits per 1,000 lines, and read in that order. I added this ranking, along with plain smallest-first, after seeing the first run, so treat them as a hypothesis the other seven runs had to confirm.
| Order, read until 20% of lines | Sphinx 2024-25 | pytest 2024-25 | Best of 9 in all 8 runs |
|---|---|---|---|
| Commits per 1,000 lines | 34.9% | 31.7% | 8 of 8 |
| Smallest files first | 33.9% | 26.2% | 0 of 8 |
| Past bug-fix commits | 26.3% | 25.9% | 0 of 8 |
| Number of authors | 22.6% | 26.3% | 0 of 8 |
| Random order | 20.6% | 19.9% | |
| Commit count (churn) | 9.6% | 28.7% | 0 of 8 |
| Hotspot (churn x complexity) | 1.7% | 23.1% | 0 of 8 |
| Cyclomatic complexity | 1.7% | 17.9% | 0 of 8 |
Across all eight runs, commits per 1,000 lines found 27.0% to 37.3% of later fix touches in the first 20% of lines. Complexity order did worse than random in 8 of 8 runs. Hotspot order did worse than random in 5 of 8, all four Sphinx runs among them.
pytest is kinder to the hotspot. Its three biggest, most complex files (python.py, config/__init__.py, fixtures.py) really are where fixes land, with 22, 28 and 25 bug-fix touches in 2024-2025, and hotspot order finds 23.1%, a bit above random. It still loses to churn per line, and it loses to raw churn too.
None of this is new to the research literature, which is a little embarrassing for the advice I gave earlier. Koru and colleagues reported in 2009 that smaller modules are proportionally more defect-prone, and Yang and colleagues showed at FSE 2016 that an unsupervised "smallest first" ordering could beat supervised defect models once effort is counted. My numbers line up with both. What I hadn't seen anyone put plainly is the consequence for the hotspot dashboards teams actually run: the formula's complexity term drags it toward exactly the files that are least bug-dense per line.
How much noise is in the bug-fix label?
A lot, and it isn't the same in both repos. I drew 40 random labelled commits and 40 random unlabelled ones from each repo's main run and read every one.
| Hand check, 2024-2025 commits | Sphinx | pytest |
|---|---|---|
| Broad rule: labelled commits that are real product fixes | 31 of 40 | 16 of 40 |
| Strict rule (subject only, no typo/lint/docs/tests/typing): real fixes | 26 of 28 | 12 of 15 |
| Unlabelled commits that are real fixes the rule missed | 3 of 40 | 3 of 40 |
pytest is the noisy one, because many of its commits close an issue in the body ("fixes #12652") whether the change was a bug fix, a feature or a doc tweak, and [pre-commit.ci] auto fixes matches too. Sphinx's false positives are mostly "Fix mypy errors" and "Fix typos". On the miss side, Sphinx says "Restore" and "Reinstate" for regressions, which no fix-regex will catch.
Three of 40 is 7.5%, with a wide interval, and there are 924 unlabelled Sphinx commits in the window. So my rule may have found anything from about a quarter to most of the real fixes. That's why I ran every score three ways: the broad rule, the strict rule, and a version where each fix commit counts once in total, split across the files it touched. Churn per line stayed the best order in 8 of 8 runs on the broad outcome, 7 of 8 on the split version and 6 of 8 on the strict one. Complexity stayed worse than random in 8 of 8 under all three. The conclusion survives the noise. The decimals don't.
What I'd do with this
Drop complexity from the hotspot score, or at least stop sorting by the product. On these two repos the complexity term made the ranking worse every time it was charged for reading. Sorting by raw cyclomatic complexity was the most consistently bad order I tested, which fits what I found when a complexity gate passed anyway after I moved code around: the number tracks how much code there is more than where it's going wrong.
Sort by commits per 1,000 lines over the last two years. It's one git log --numstat and one line counter. If you want a second column, use past bug-fix commits, which ranked third and needs only the regex above.
And watch the denominator. Reading 20% of Sphinx's lines in churn-per-line order meant opening 99 of its 173 files, median size 87 SLOC. Five of the top entries are empty __init__.py files that score highest simply because they have no code lines at all, only docstrings. In practice I'd set a floor of 50 SLOC and review the rest in batches, a directory at a time. I'm fairly sure a reviewer gets more out of 99 short files than out of cpp.py, but that's my opinion, and the per-file overhead is real.
The disagreeable part: I think a hotspot map built on churn times complexity is mostly a size map with a nicer name, and teams that use it to pick refactoring targets end up rewriting their biggest stable modules while the bugs keep landing in small, busy files nobody looks at.
What I didn't measure
- Two repos, one language. Both are Python libraries with disciplined maintainers. An application codebase, or a C tree where one file is a whole subsystem, could behave differently.
- Bugs, not debt. Bug-fix touches are one form of interest. Slow changes, onboarding time and blocked features don't show up here at all.
- Splits. Sphinx broke several large modules into packages in 2024-2025. Bug-fix touches on package files that map back to no starting file were counted separately: 15 in each main run, against 127 (Sphinx) and 327 (pytest) mapped ones. Hotspot order would still sit below random on Sphinx even if all 15 belonged to its top files.
- One reader. The 160 commits in the hand check are my judgment, with no second opinion.
- Function level. Everything here is per file. A per-function hotspot might rank differently.
- Other complexity tools. I used radon only, so I didn't check whether lizard's counts would change anything. With a 0.983 correlation between hotspot and complexity, I doubt it would.
- Severity. A crash fix and a wrong default count the same.
Everything, including the scripts, the per-file rows and my hand-labelled sample, is in examples/technical-debt-signals-where-bugs-get-fixed/. run_all.sh clones both repos at the pinned heads and rebuilds every number above.