Skip to content

perf: Return a single-index result of [.igraph.vs without c() - #2940

Open
schochastics wants to merge 1 commit into
perf/vs-lazy-names-benchfrom
perf/vs-index-single-result
Open

schochastics wants to merge 1 commit into
perf/vs-lazy-names-benchfrom
perf/vs-index-single-result

Conversation

@schochastics

@schochastics schochastics commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Split 2 of 3 from #2696, per #2696 (comment).
Stack: #2939 -> this -> #2696.

Change

With a single index argument, [.igraph.vs passed its one result through c().
c.igraph.vs() re-parses the sequence and wraps it again, which mints a fresh weak reference to the graph.
The result is now returned as is, as [.igraph.es already does.

The returned sequence has the same values, names, class and graph ID as before.
The only difference is that it now shares the input's weak reference instead of holding a new one to the same graph, in line with #2886.

Benchmarks

Local, release builds of main vs. this branch, median of 4 interleaved fresh processes (bench::mark()), touchstone setups:

main this PR
V(g)[color == "red"] (vs_attr_filter) 134.7 µs 89.2 µs −34%
V(g)[pick] (vs_by_name) 65.6 µs 66.3 µs unchanged

vs_by_name is unchanged because indexing with a plain variable already returns early, before c().

Verification

  • New test: single-argument results (by name and by attribute filter) share the input's env reference and give the expected vertices; a two-argument index still concatenates.
  • Full test suite passes locally.

🤖 Generated with Claude Code

With one index argument, `[.igraph.vs` passed its result through `c()`, which re-parses the sequence and mints a fresh weak reference to the graph.
The result is now returned as is, as `[.igraph.es` already does, so it keeps sharing the input's reference.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 72ded03 is merged into perf/vs-lazy-names-bench:

  • ✔️E_named: 224ms -> 224ms [-1.9%, +1.84%]
  • ✔️V_named: 540ms -> 540ms [-2.34%, +2.56%]
  • ✔️all_simple_paths_named: 135ms -> 135ms [-0.39%, +0.12%]
  • ✔️as_adjacency_matrix: 248ms -> 248ms [-0.36%, +0.61%]
  • 🚀as_biadjacency_matrix: 266ms -> 265ms [-1.03%, -0.12%]
  • ✔️as_data_frame_both: 263ms -> 255ms [-9.18%, +3.11%]
  • ✔️as_long_data_frame: 197ms -> 197ms [-0.83%, +0.42%]
  • ✔️ego_order2_named: 148ms -> 150ms [-0.97%, +3.93%]
  • ✔️es_attr_assign: 239ms -> 242ms [-1.9%, +4.69%]
  • ✔️es_attr_filter: 240ms -> 239ms [-2.01%, +1.39%]
  • ✔️graph_from_adjacency_matrix: 286ms -> 287ms [-0.33%, +0.81%]
  • 🚀graph_from_data_frame: 270ms -> 268ms [-1.53%, -0.46%]
  • ✔️head_of_named: 171ms -> 171ms [-0.28%, +0.36%]
  • ✔️incident_edges: 194ms -> 194ms [-0.72%, +0.05%]
  • ✔️max_cliques_named: 25.5ms -> 25.5ms [-0.7%, +0.38%]
  • ✔️max_cliques_sizes_named: 210ms -> 210ms [-0.32%, +0.35%]
  • ❗🐌neighbors_by_name: 259ms -> 260ms [+0.14%, +0.87%]
  • ✔️union_named: 234ms -> 235ms [-0.99%, +1.83%]
  • 🚀vs_attr_filter: 301ms -> 202ms [-33.46%, -32.49%]
  • ✔️vs_by_name: 247ms -> 245ms [-2.06%, +0.77%]
  • ✔️vs_subset_positional: 271ms -> 273ms [-0.32%, +1.89%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant