OpenCut's timeline and audio layer carries the highest activity risk — 5 functions to address first

OpenCut's top hotspots cluster in its timeline interaction hooks and audio management core, where god-function patterns and fan-out above 40 combine with recent commit activity levels above 13 across all five critical functions.

Stephen Collins ·
oss typescript refactoring code-health

Antipatterns Detected

exit_heavy5long_function4complex_branching3god_function3deeply_nested2

Key Points

What is a god function and why does it matter in OpenCut?

A god function is one that has taken on so many responsibilities that it becomes the central coordinator for a wide swath of the application. In OpenCut, `useTimelineDragDrop` and `useElementInteraction` both carry this pattern — they each call dozens of other functions, which means a change to either one can ripple through much of the timeline subsystem in ways that are hard to predict or test fully.

How do I reduce cyclomatic complexity in TypeScript?

Extract each major conditional branch into a named function with a clear single responsibility, and replace long if-else chains with lookup tables or strategy objects where the branching condition is data-driven — `parseTimeCode`'s CC of 53 is a strong candidate for a format-to-parser map that replaces most of its branches.

Is OpenCut actively maintained?

The activity data strongly suggests yes — all five top hotspots have recent commit activity levels between 13.87 and 15.46, indicating frequent recent commits to exactly the functions that are already structurally complex, which is characteristic of a codebase under active feature development.

How do I reproduce this analysis?

Run the Hotspots CLI against the OpenCut repository at commit dc58c10 to reproduce the scores reported 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 dc58c10, OpenCut’s highest activity-weighted risk is concentrated in its timeline interaction layer and audio pipeline: useTimelineDragDrop carries a recent commit activity of 15.46 — meaning it is not merely complex but is being actively changed right now, making structural issues a live regression risk rather than a deferred cleanup item. Across 2,797 total functions, 123 are rated critical, and all five top hotspots sit in the ‘fire’ quadrant, where high structural complexity and high recent commit activity intersect. OpenCut is an open-source video editor; these functions sit at the core of its editing UX and media playback, which explains both the complexity and the pressure to keep changing them.

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
useTimelineDragDropapps/web/src/hooks/timeline/use-timeline-drag-drop.ts16.615542
runClipIteratorapps/web/src/core/managers/audio-manager.ts15.41858
useElementInteractionapps/web/src/hooks/timeline/element/use-element-interaction.ts15.118337
parseTimeCodeapps/web/src/lib/time.ts15.15335
collectAudioElementsapps/web/src/lib/media/audio.ts15.018412

Hotspot Analysis

useTimelineDragDrop — apps/web/src/hooks/timeline/use-timeline-drag-drop.ts

Based on its name and location in the timeline hooks directory, this function almost certainly manages the drag-and-drop interaction model for the video editing timeline — one of the most state-intensive surfaces in any editor. Its fan-out of 42 is the highest in the dataset, meaning it calls 42 distinct functions and is broadly coupled to the rest of the application; a change here has an unusually wide blast radius. With CC 15, ND 5, and a recent commit activity of 15.46, the function is both structurally complex and actively changing — the detected god-function and deeply-nested patterns confirm it is accumulating responsibilities that belong elsewhere, and every new commit to it is made against a backdrop of 15 independent execution paths and 5 levels of nesting.

Recommendation: Before the next feature addition, write characterization tests that cover the major drag event paths (given CC 15, aim for at least 15 test cases), then extract discrete sub-hooks — for example, drop-target resolution, snap-to-grid logic, and ghost-element positioning — to reduce fan-out and isolate future change blast radius.

runClipIterator — apps/web/src/core/managers/audio-manager.ts

The name and location suggest this function iterates over audio clips within the audio manager — likely advancing playback state, handling clip boundaries, or scheduling audio segments frame by frame. Its CC of 18 means 18 independent execution paths through what is probably a tight media-clock loop, and its ND of 5 indicates deeply nested conditional logic that is hard to reason about in isolation. With an activity-weighted risk score of 15.38, this is the second most urgent function in the codebase — the complex_branching and exit_heavy patterns flag that many of those 18 paths terminate early, each one a gap where test coverage can silently lapse as the code evolves.

Recommendation: Map each of the 18 cyclomatic paths to an explicit test case before refactoring; then apply extract-method to pull early-exit guard clauses into named predicate functions, which will reduce nesting depth and make the branching structure visible at a glance.

useElementInteraction — apps/web/src/hooks/timeline/element/use-element-interaction.ts

Sitting one level deeper in the timeline hook hierarchy than useTimelineDragDrop, this function likely handles pointer and keyboard interactions scoped to individual timeline elements — clicks, drags, selections, and possibly resize handles. Its fan-out of 37 is almost as wide as useTimelineDragDrop’s 42, confirming it is a second god-function in the same subsystem, and with CC 18 it has 18 independent paths despite a relatively shallow ND of 3 — meaning the branching is wide rather than deeply nested. A recent commit activity of 14.0 confirms it is under active development, so its 18 exit paths (the exit_heavy pattern) represent 18 places where a change can introduce a regression that existing tests may not catch.

Recommendation: Audit the 37 fan-out callees to identify which belong to drag-drop concerns already handled by useTimelineDragDrop; consolidating overlapping responsibilities between these two hooks would reduce coupling in both functions simultaneously and is a higher-leverage move than line-level cleanup.

Patterns Found

Antipatterns detected across the top functions in this snapshot:

PatternOccurrences
exit_heavy5
long_function4
complex_branching3
god_function3
deeply_nested2

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

  • useTimelineDragDrop has a fan-out of 42 — the broadest coupling surface in the top hotspots — so any refactoring session should start by mapping its 42 callees and partitioning them into cohesive sub-hooks before touching any logic.
  • parseTimeCode in apps/web/src/lib/time.ts has a CC of 53 — more than three times higher than the next most complex hotspot — yet only 5 fan-out callees, making it an isolated but extreme branching risk; it is the single highest-priority candidate for a table-driven or regex-based rewrite to collapse its 53 paths.
  • All five critical functions share the exit_heavy pattern, meaning test suites must cover early-return branches explicitly; before any refactoring sprint, run a coverage report scoped to these five files and treat uncovered exit paths as blocking gaps.

Reproduce This Analysis

git clone https://github.com/OpenCut-app/OpenCut
cd OpenCut
git checkout dc58c10e64fae45f370b42494ebe0a74561a0c2d
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