perf: Batch-construct vertex sequence lists via create_vs_list() - #2887
Open
schochastics wants to merge 1 commit into
Open
perf: Batch-construct vertex sequence lists via create_vs_list()#2887schochastics wants to merge 1 commit into
schochastics wants to merge 1 commit into
Conversation
Functions returning many vertex sequences used `lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))`, which re-read the graph reference, graph id and name source from `verts` on every object. Add `create_vs_list(graph, idx_list)`, which hoists all of that per-graph work out of the loop and builds each sequence with a single `attributes<-`, so per-object cost drops to an integer coercion, a name subset and one attribute set. The `VERTEXSET_LIST` OUTCONV template in tools/stimulus/types-RR.yaml now emits `create_vs_list(graph, res)`; the generated R/aaa-*.R files are updated to match (27 sites), along with the hand-written call sites in cliques.R, cohesive.blocks.R, components.R, conversion.R, interface.R, paths.R and structural-properties.R (10 sites). `unsafe_create_vs()` stays as the single-object form. Beyond the speedup this gives the construction loop a single named entry point, so it can later be moved wholesale (e.g. into C) without touching any call site. Edge sequences are left as-is: simple_es_index() already propagates the shared weak reference from a single E(graph), so unsafe_create_es() does not pay the per-object cost. An es batch form remains a follow-up. max_cliques(sample_gnp(200, 0.16)) on a named graph: ~7.8ms -> ~5.6ms. Output, names, NA handling and graph recovery are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Sep 4, 2026
Contributor
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if dec29d7 is merged into perf/vs-shared-weakref:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split 2 of 4 out of #2696, per #2696 (comment) — this is the requested
lapply()->create_vs_list()step.Base: #2886 (review that first; this PR's diff is only the top commit). Next in the stack: #2888.
What changed
37 call sites built lists of vertex sequences with
which re-reads the graph reference, the graph id and the name source out of
vertson every single object.create_vs_list(graph, idx_list)hoists all of that per-graph work out of the loop, so each sequence costs oneas.integer(), one name subset and oneattributes<-.VERTEXSET_LISTOUTCONVtemplate intools/stimulus/types-RR.yamlnow emitscreate_vs_list(graph, res), and the generatedR/aaa-*.Rfiles are updated to match (27 sites).cliques.R,cohesive.blocks.R,components.R,conversion.R,interface.R,paths.R,structural-properties.R(10 sites).unsafe_create_vs()stays as the single-object form.max_cliques(sample_gnp(200, 0.16))on a named graph: 7.8 ms -> 5.6 ms (24.7 ms onmain).Why it matters beyond the numbers
This is the enabling refactor. It gives "turn this list of ID vectors into a list of vertex sequences" a single named entry point, so the construction loop can later be moved wholesale — into C in #2888, and behind lazy names in #2696 — without touching any of the 37 call sites again. Both of those PRs change only the body of this one function.
Scope
Edge sequences are deliberately left alone:
simple_es_index()already propagates the shared weak reference from a singleE(graph), sounsafe_create_es()does not pay the per-object cost. Ancreate_es_list()batch form remains a follow-up.Correctness
Output, names, NA handling and graph recovery are unchanged — this is a pure refactor of where the per-graph lookups happen.
Full suite: FAIL 0 | WARN 0 | SKIP 7 | PASS 9299.