Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertex access speedups #197

Merged
merged 6 commits into from
Jul 12, 2022
Merged

Vertex access speedups #197

merged 6 commits into from
Jul 12, 2022

Conversation

cfhammill
Copy link
Contributor

A speed up for ego and as_adj_list, this goes without adjusting igraph_opt("return.vs.es") so it will benefit users automatically. Time reduction for as_adj_list on a 40000 node graph dropped from 500 -> 9 seconds. The key time saver is only computing V(graph) once. This is done with the new unsafe_create_vs function documented in code and the commit message. Still ~100 fold slower than igraph_options(return.vs.es = FALSE), but you get the benefit of reclassing the integer vectors igraph.vs and associating the graph pointer.

cfhammill and others added 4 commits May 25, 2017 13:10
Update documentation to point out that this option exists.
This prevent any(is.na(vs)) from getting evaluated if na.ok = TRUE
This is intended to be useful when the vertex indices
are guaranteed to be in the set of possible vertices.
This is true particularly after C-code when domain
checks are clearly unnecessary. Also allows vertices
to be pre-computed. This speeds up as_adj_list and
ego
Copy link
Member

@vtraag vtraag left a comment

Choose a reason for hiding this comment

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

This looks potentially quite useful, thanks for contributing!

I was thinking about one thing however. You are saying that the key time saver is the computation of V(graph) only once. I therefore wonder whether it would not be better to simply keep the existing create_vs function, but add the optional verts argument you now added to unsafe_create_vs? I am not sure of the performance impact of the ifelse, but I can imagine that is relatively minor. That is, we could hence have no need of the unsafe_create_vs and only have the "safe" create_vs function, but which can potentially be sped up if we pass in the vertices. There are a few other such use cases in the code base that might benefit from a similar speed up. What do you think about this?

R/iterators.R Outdated Show resolved Hide resolved
R/iterators.R Show resolved Hide resolved
@ntamas
Copy link
Member

ntamas commented Sep 24, 2021

This PR seems okay to be, but there are multiple occurrences of lapply(...,create_vs, ...) in the codebase; @vtraag do you think it would be safe to also replace them with lappy(..., unsafe_create_vs, ...)? Most of the examples are in cliques.R and structural.properties.R.

Copy link
Member

@ntamas ntamas left a comment

Choose a reason for hiding this comment

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

I think I am familiar enough with the R codebase to judge that this is safe to merge. Thanks a lot for your contribution, and sorry about the delay!

@ntamas ntamas merged commit ba04339 into igraph:dev Jul 12, 2022
github-actions bot pushed a commit that referenced this pull request Jul 12, 2022
* Speed up  if igraph_opt(return.vs.es) is false

Update documentation to point out that this option exists.

* Change condition in simple_vs_index to allow short-circuit

This prevent any(is.na(vs)) from getting evaluated if na.ok = TRUE

* Add unsafe_create_vs

This is intended to be useful when the vertex indices
are guaranteed to be in the set of possible vertices.
This is true particularly after C-code when domain
checks are clearly unnecessary. Also allows vertices
to be pre-computed. This speeds up as_adj_list and
ego

* undo change to simple_vs_index

Co-authored-by: Vincent Traag <vincent@traag.net>
Co-authored-by: Tamás Nepusz <ntamas@gmail.com> [Triggered by ba04339]
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants