Skip to content

refactor: remove unreachable Partition delta-computation interface methods#1896

Open
carlos-alm wants to merge 1 commit into
fix/issue-1769-codegraph-method-attributionfrom
fix/issue-1770-leiden-partition-dead-code
Open

refactor: remove unreachable Partition delta-computation interface methods#1896
carlos-alm wants to merge 1 commit into
fix/issue-1769-codegraph-method-attributionfrom
fix/issue-1770-leiden-partition-dead-code

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

Closes #1770

Test plan

  • npm test — full suite green (3545 passed, 0 failed)
  • npm run lint / npm run typecheck — clean
  • Community detection confirmed byte-identical: 36 combinations (file/function level × modularity/CPM × 3 resolutions × 3 seeds) on this repo's own 920-file graph, before/after SHA-256 hashes matched exactly

Filed #1895 for codegraph's own dead-code detector blind spot found during investigation: object-literal property-value references count as liveness without checking if the property is ever invoked (not fixed here, out of scope).

Stacked on #1894 (base branch fix/issue-1769-codegraph-method-attribution) — only the leiden/test diff is this issue's change.

…thods

optimiser.ts's computeQualityGain (the only caller of CPM/modularity delta
computation in the Leiden hot loop) calls the standalone diffCPM/diffModularity
functions directly — it never calls partition.deltaCPM(...),
partition.deltaModularityDirected(...), or partition.deltaModularityUndirected(...).
Confirmed via repo-wide grep that these three Partition interface methods,
plus getCandidateCommunityCount, have zero callers in src/, tests/, or scripts,
and that Partition/makePartition are not part of the public API (src/index.ts).

Verified dead empirically, not just statically: replaced each of the four
functions' bodies with a throw and ran the full test suite (3549 tests) —
all passed, proving no code path anywhere reaches them. This also revealed
that the "directed modularity delta — exact regression" tests added by #1755
(pinning computeDeltaModularityDirected's assumed output) actually exercise
a different function — diffModularityDirected in modularity.ts, reached via
computeQualityGain — since detectClusters never calls the Partition interface
method. Corrected that test's comment accordingly instead of leaving it
pointing at a deleted function.

Removed:
- The four dead Partition interface methods (deltaCPM, deltaModularityDirected,
  deltaModularityUndirected, getCandidateCommunityCount) and their backing
  implementations (computeDeltaCPM, computeDeltaModularityDirected,
  computeDeltaModularityUndirected, and the CPM/directed-term helper
  functions extracted in #1755/phase-22 that existed solely to serve them).
- fgetOrZero (typed-array-helpers.ts), which becomes fully unreachable once
  computeDeltaModularityDirected (its only caller) is gone — it was extracted
  in #1755 specifically for that function. Removed its direct unit-test block
  along with it.

Chose removal over wiring computeQualityGain to the Partition methods
(deduplicating diffCPM/diffModularity vs. computeDeltaCPM/computeDeltaModularityDirected/
computeDeltaModularityUndirected) because the two implementations read through
different data-access layers (raw PartitionState typed arrays vs. the
PartitionView getter interface) — swapping which one runs in the Leiden hot
loop would need rigorous before/after numerical verification on real data to
rule out subtle divergence, on a file with a track record of exactly that
kind of bug (#1734, #1755). Removal of genuinely unreachable code carries
none of that risk.

Verified no behavioral change: built this repo's own dependency graph (920
files / 19285 function-level nodes) and ran detectClusters directly (bypassing
louvainCommunities' native-Rust preference to exercise the changed JS path)
at file- and function-level granularity, both modularity and CPM quality
functions, 3 resolutions x 3 random seeds (36 combinations) — before/after
membership + quality() output is byte-for-byte identical (matching SHA-256).
Also confirmed `codegraph communities -T --json` and `npm run typecheck`/
`npm run lint`/`npm test` (216 files, 3545 passed, 30 skipped, 2 todo) are
unaffected.

Filed #1895 to track codegraph's own dead-code detector blind spot (an
object-literal-property-value reference counts as liveness without checking
whether the resulting property is ever invoked) — out of scope to fix here.

diff-impact --staged: 1 function changed (makePartition) -> 4 transitive
callers across 2 files, all of which only use surviving Partition methods.

Fixes #1770

docs check acknowledged

Impact: 1 functions changed, 4 affected
@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR removes four dead interface methods (deltaCPM, deltaModularityUndirected, deltaModularityDirected, getCandidateCommunityCount) from the Partition interface and their implementations in partition.ts, along with the fgetOrZero helper in typed-array-helpers.ts that was only consumed by those removed functions. The test file is updated to remove the direct unit tests for the deleted code and to correct a misattributed comment that had claimed the regression test exercised Partition.deltaModularityDirected (which is unreachable) rather than diffModularityDirected in modularity.ts.

  • partition.ts: Removes ~160 lines of dead delta-computation functions (computeDeltaModularityUndirected, computeDeltaModularityDirected, computeDeltaCPM, and their helpers) plus the four interface method bindings; all live callers go through computeQualityGaindiffCPM/diffModularity in optimiser.ts instead.
  • typed-array-helpers.ts: Removes fgetOrZero (introduced in leiden/partition.ts: computeDeltaModularityDirected exceeds cyclomatic threshold (cyc=11) #1755 solely for the now-deleted functions), keeping the file lean with only fget, iget, u8get, and taAdd.
  • leiden.test.ts: Drops the fgetOrZero unit tests (function no longer exists) and rewrites the regression-test comment to correctly describe the actual code path being exercised.

Confidence Score: 5/5

Safe to merge — removes verified dead code with no live callers; all 3549 tests pass and community detection output is byte-identical before and after.

The deleted interface methods have zero callers in the codebase (confirmed by grepping src/), the actual hot-loop computation routes exclusively through standalone diffCPM/diffModularity functions in optimiser.ts, and the PR description documents an empirical proof (replacing the functions with throw left the full test suite green). The only change to surviving code is the test comment correction, which is accurate.

No files require special attention — all three files are straightforward deletions or comment corrections with no logic changes to surviving code paths.

Important Files Changed

Filename Overview
src/graph/algorithms/leiden/partition.ts Removes 4 dead interface methods and ~160 lines of delta-computation implementation; remaining code is unchanged and the interface stays internally consistent.
src/graph/algorithms/leiden/typed-array-helpers.ts Removes fgetOrZero (now orphaned after the partition.ts deletion); no remaining callers exist anywhere in the codebase.
tests/graph/algorithms/leiden.test.ts Drops fgetOrZero import and its 4 direct unit tests; corrects misattributed comment on the directed-modularity regression test to reflect the actual live call path.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[optimiser.ts\ncomputeQualityGain] -->|quality === 'cpm'| B[cpm.ts\ndiffCPM]
    A -->|quality === 'modularity'| C[modularity.ts\ndiffModularity]
    C -->|graph.directed| D[modularity.ts\ndiffModularityDirected]
    C -->|undirected| E[modularity.ts\ndiffModularityUndirected]

    subgraph removed["Removed dead code (this PR)"]
        F["Partition.deltaCPM()"]
        G["Partition.deltaModularityDirected()"]
        H["Partition.deltaModularityUndirected()"]
        I["Partition.getCandidateCommunityCount()"]
        J["fgetOrZero() in typed-array-helpers.ts"]
    end

    style removed fill:#fee2e2,stroke:#ef4444,color:#7f1d1d
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[optimiser.ts\ncomputeQualityGain] -->|quality === 'cpm'| B[cpm.ts\ndiffCPM]
    A -->|quality === 'modularity'| C[modularity.ts\ndiffModularity]
    C -->|graph.directed| D[modularity.ts\ndiffModularityDirected]
    C -->|undirected| E[modularity.ts\ndiffModularityUndirected]

    subgraph removed["Removed dead code (this PR)"]
        F["Partition.deltaCPM()"]
        G["Partition.deltaModularityDirected()"]
        H["Partition.deltaModularityUndirected()"]
        I["Partition.getCandidateCommunityCount()"]
        J["fgetOrZero() in typed-array-helpers.ts"]
    end

    style removed fill:#fee2e2,stroke:#ef4444,color:#7f1d1d
Loading

Reviews (1): Last reviewed commit: "refactor: remove unreachable Partition d..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

1 functions changed4 callers affected across 2 files

  • makePartition in src/graph/algorithms/leiden/partition.ts:378 (4 transitive callers)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant