comprehensive-rust's theme layer carries the highest activity risk — 4 functions to address first

Four of the top five hotspots in google/comprehensive-rust live in theme/book.js and theme/speaker-notes.js, driven by extreme fan-out and active commit churn at commit a5c5154.

Stephen Collins ·
oss rust refactoring code-health

Antipatterns Detected

exit_heavy5long_function4god_function3

Key Points

What is a god function and why does it matter in comprehensive-rust?

A god function is one that does too much — it reaches into a large number of other functions and owns too many responsibilities at once. In comprehensive-rust, codeSnippets in theme/book.js calls into 72 distinct other functions, meaning a single change there can have ripple effects across a wide swath of the UI layer. That breadth makes it disproportionately difficult to change safely and dramatically increases the surface area for unintended side effects.

How do I reduce fan-out in JavaScript theme code?

Group the callees by responsibility — for example, separating DOM manipulation from event handling from storage access — and extract each group into its own named module or function, so no single function owns more than one concern.

Is comprehensive-rust actively maintained?

Yes — the top four hotspots all sit in the 'fire' quadrant, meaning they are both structurally complex and actively changing. Their activity-weighted risk scores are 14.7, 14.0, 13.9, and 12.5 respectively, indicating the theme layer is being changed right now, not just carrying historical debt.

How do I reproduce this analysis?

Run the Hotspots CLI against google/comprehensive-rust at commit a5c5154 to get the same results shown here.

What does activity-weighted risk mean?

Complexity × recent commit frequency — functions that are hard to understand AND actively changing are the highest priority for refactoring.

At commit a5c5154, four of the five highest-priority functions in google/comprehensive-rust live in the JavaScript theme layer — specifically theme/book.js and theme/speaker-notes.js — all in the ‘fire’ quadrant, meaning they are both structurally complex and actively changing today. The anonymous function in speaker-notes.js leads with an activity-weighted risk of 14.7 — the highest in the dataset — making it a live regression risk rather than a backlog item. Across 409 total functions, 17 are rated critical and 46 high — a meaningful concentration of structural risk for a project that serves as a reference teaching resource for the Rust language.

The table below ranks functions by activity-weighted risk — a score that multiplies structural complexity by recent commit frequency. A function that is both hard to understand (high cyclomatic complexity) and actively changing is a higher priority than one that is complex but untouched. CC = cyclomatic complexity (independent execution paths); ND = max nesting depth; FO = fan-out (distinct callees).

Top 5 Hotspots

FunctionFileRiskCCNDFO
<anonymous>theme/speaker-notes.js14.719343
codeSnippetstheme/book.js14.09372
themestheme/book.js13.923232
<anonymous>theme/book.js12.52127
mainsrc/exercises/bare-metal/compass/src/main.rs11.8934

Codemod / Tooling Files in Results

All five top hotspots include files from the theme/ directory: theme/speaker-notes.js, theme/book.js, and theme/book.js contain the top four critical functions. These are JavaScript theme files that ship with the mdBook toolchain used to render the course — they are part of the book’s front-end layer rather than the Rust instructional content itself. Because they are project-owned theme customizations rather than purely vendored third-party code, they remain valid refactoring targets; however, if your team treats the theme directory as out-of-scope, you can exclude it with: { "exclude": ["theme/"] } in your .hotspotsrc.json. The bare-metal compass main.rs remains the only first-party Rust hotspot in the top five.

Hotspot Analysis

<anonymous> — theme/speaker-notes.js

Based on its name and path, this anonymous function is the core initialization or event-handling routine for the speaker notes panel in the mdBook theme — likely coordinating communication between the slide view and a companion notes window. Its fan-out of 43 means it reaches into 43 distinct callees, creating a broad coupling surface where any downstream change can ripple back here unexpectedly. A cyclomatic complexity of 19 means 19 independent execution paths must be reasoned about and tested, and with an activity-weighted risk of 14.7 in the ‘fire’ quadrant, this is a live regression risk: the code is both hard to understand and actively being changed right now.

Recommendation: Before the next commit touches this function, extract the discrete responsibilities — window management, message passing, UI state — into named, single-purpose functions to reduce the fan-out and bring CC below 10. Add characterization tests first to document current behavior and catch regressions.

codeSnippets — theme/book.js

The name and path suggest this function handles the rendering and interaction logic for code snippet blocks in the book’s theme — copy buttons, line highlighting, language labels, and similar behaviors. Its fan-out of 72 is the highest in the entire top-five list and flags it as a god function with extreme coupling breadth: 72 distinct callees means a change here can propagate to an unusually large number of other components. With an activity-weighted risk of 14.0 in the ‘fire’ quadrant, this coupling is being stressed right now, and the exit-heavy pattern means multiple return paths add to the test-coverage burden.

Recommendation: Map the 72 fan-out targets to identify which groups of callees represent distinct concerns — e.g., DOM manipulation, clipboard access, syntax highlighting — and extract each group into its own focused function. Prioritize this over other book.js work given it has the highest raw fan-out in the dataset.

themes — theme/book.js

Based on its name and location, this function likely manages theme switching logic — loading, persisting, and applying visual themes to the book UI. A cyclomatic complexity of 23 indicates 23 distinct execution paths, which is firmly in the high range and suggests extensive conditional branching over theme names, storage states, or user preferences. At an activity-weighted risk of 13.9 in the ‘fire’ quadrant alongside a fan-out of 32, active changes to this branching-heavy function carry meaningful regression risk across the theme subsystem.

Recommendation: Refactor the branching logic using a dispatch table or strategy pattern to reduce the CC below 10, then extract each theme’s application logic into its own named function — this will also reduce fan-out and make each path independently testable.

Patterns Found

Antipatterns detected across the top functions in this snapshot:

PatternOccurrences
exit_heavy5
long_function4
god_function3

These labels belong to two tiers — Tier 1 (structural): complex_branching, deeply_nested, exit_heavy, long_function, god_function. Tier 2 (relational/temporal): hub_function, cyclic_hub, middle_man, neighbor_risk, stale_complex, churn_magnet, shotgun_target, volatile_god.

Key Takeaways

  • The anonymous function in theme/speaker-notes.js has an activity-weighted risk of 14.7 and fan-out of 43 — extract its responsibilities into named functions before the next commit to prevent live regressions.
  • codeSnippets in theme/book.js has a fan-out of 72, the highest in the dataset — map its 72 callees into cohesive groups and extract each into a dedicated function to contain blast radius.
  • The themes function in theme/book.js has cyclomatic complexity of 23, meaning at least 23 test cases are needed to cover every path — replace the branching logic with a dispatch table and verify coverage before any further theme changes.

Reproduce This Analysis

git clone https://github.com/google/comprehensive-rust
cd comprehensive-rust
git checkout a5c515433c5964ce9e746d69efd8a2d8e640ee8d
hotspots analyze . --mode snapshot --explain-patterns --force

To run the same analysis on your own codebase, run hotspots analyze . --mode snapshot in any local git repo — no configuration required.

Hotspots highlights structural and activity risk — not “bad code.” Findings are a prioritization aid, not a bug predictor. Editorial policy →

Run this on your own codebase

Hotspots runs locally in under a minute — no account, no data leaves your machine.

macOS
$ brew install Stephen-Collins-tech/tap/hotspots
Linux / cargo
$ cargo install hotspots-cli
Run in any repo
$ hotspots analyze .
★ Star on GitHub

Related Analyses