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
| Function | File | Risk | CC | ND | FO |
|---|---|---|---|---|---|
<anonymous> | theme/speaker-notes.js | 14.7 | 19 | 3 | 43 |
codeSnippets | theme/book.js | 14.0 | 9 | 3 | 72 |
themes | theme/book.js | 13.9 | 23 | 2 | 32 |
<anonymous> | theme/book.js | 12.5 | 21 | 2 | 7 |
main | src/exercises/bare-metal/compass/src/main.rs | 11.8 | 9 | 3 | 4 |
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:
| Pattern | Occurrences |
|---|---|
exit_heavy | 5 |
long_function | 4 |
god_function | 3 |
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 →