Skip to content

Build the call graph once in findFunctionCyclesVia - #935

Open
JonasAlaif wants to merge 3 commits into
viperproject:masterfrom
JonasAlaif:function-cycles-perf
Open

JonasAlaif wants to merge 3 commits into
viperproject:masterfrom
JonasAlaif:function-cycles-perf

Conversation

@JonasAlaif

Copy link
Copy Markdown
Contributor

findFunctionCyclesVia (used by the checkNoFunctionRecursesViaPreconditions consistency check) rebuilt the call graph of the whole program once per function, so the check was quadratic in the number of functions. On Prusti-generated programs it took 20-70s for ~1.5k-3k functions, and much longer for larger ones.

This collects the callees of every function once, and searches each function's cycles only within its strongly connected component of the graph that has both the via and subs edges (every per-function graph is a subgraph of it). Callees keep their original order, since the cycle sets reported by jgrapht's CycleDetector depend on the edge traversal order.

The results are identical to the old implementation (compared on 3000 random programs and several large Prusti-generated ones), e.g. 69s -> 0.1s for a program with 3207 functions.

findFunctionCyclesVia rebuilt the call graph of the whole program for every
function, which made the consistency check quadratic in the number of
functions (e.g. over a minute for a program with 3k functions). Collect the
callees of every function once and search each function's cycles only in its
strongly connected component of the graph with both kinds of edges.

Written with Claude
@JonasAlaif
JonasAlaif requested a balanced review from Copilot October 1, 2026 13:23

This comment was marked as spam.

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.

4 participants