Skip to content

perf(extract): derive candidate file facts once in call binding - #5669

Open
Max17190 wants to merge 1 commit into
Graphify-Labs:v8from
Max17190:perf/call-binding-candidate-facts
Open

Max17190 wants to merge 1 commit into
Graphify-Labs:v8from
Max17190:perf/call-binding-candidate-facts

Conversation

@Max17190

@Max17190 Max17190 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Why

Call binding recomputed facts about each candidate's file on every call. The Go import path lookup walked the ancestors for go.mod each time, the language family was derived again, and the tie breaker rebuilt set(test_cands) for each element. A cold Kubernetes build took 21 minutes. Fixes #5666.

Summary

_go_import_path_for_file now caches every directory it walks with that walk's result. extract() stores each file's language family and Go import path for the rest of the pass. The tie breaker splits candidates in one pass and caches the test path check per path.

Cold graphify update . v8 This PR
Kubernetes 1262s 437s
Django 78.9s 78.1s

Each number is the median of 3 runs on a 16 vCPU Linux machine with CPython 3.12. The output matches v8 byte for byte.

Limitations: repositories without Go or with few ambiguous names barely change, and incremental Go updates are not faster.

Test plan

python -m pytest tests -q -n 8 --dist loadfile   # 12641 passed
python -m pytest tests/test_call_binding_candidate_facts.py -q   # 4 passed; all 4 fail on v8
uv run ruff check .                              # passes
uv run pyright --pythonpath .venv/bin/python     # same diagnostics as v8
uv run python -m tools.skillgen --check          # 134 artifacts match
graphify update .   # cold on Kubernetes, Django and VS Code, and incremental on Kubernetes; identical to v8
  • Read CONTRIBUTING.md
  • AI help disclosed in the commit trailer

A common bare name brings the same candidate definitions back on every
call site, but the bare-name binding pass recomputed facts that depend
only on a candidate's source file once per candidate per call:

- the Go import path of every candidate of an imported selector call,
  which re-walked the directory ancestors probing for go.mod because the
  module cache only remembered directories that own one;
- the language family of every candidate for the cross-language guard;
- in the shared disambiguate_ambiguous_candidates tie-breaker, the
  test-path classification of every candidate, plus a set of the test
  candidates rebuilt for each element (quadratic per call).

The pass now memoizes the family and Go import path per source file for
the duration of one extract() call (the family honours .graphifyrc
suffix overrides, so the memo never outlives the pass), and the Go
package repoint below it shares the same memo. _go_import_path_for_file
caches every directory a walk visits with the walk's answer, so sibling
packages stop at the first known directory; a go.mod without a module
line still stops the walk with no import path. The tie-breaker
partitions candidates in one pass, keeping their order, and classifies
each distinct path once through a bounded memo.

Output is unchanged: graph.json, the partition cache and GRAPH_REPORT.md
are byte-identical to the previous code on cold builds of a large Go
monorepo and a Python web framework, and on an incremental Go rebuild.

Fixes Graphify-Labs#5666

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Max17190
Max17190 requested a review from safishamsi as a code owner December 1, 2026 04:45
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Thanks for the pull request, @Max17190. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Dec 1, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify review View in Graphify

Looks safe to merge · Merge confidence 5/5

No issues reported · High impact

The change memoizes source-file language and Go import-path facts during call binding, and caches Go module-walk results for visited directories.

Code graph · 7825 functions depend on this change
  • 1 function became more coupled. extract() (1454 callers).
  • 535 of 666 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed d41ef02

This branch has not been deployed

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

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Call binding recomputes candidate file facts on every call, so a cold Kubernetes build takes 21 minutes

1 participant