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

Copying large digraphs is slow #292

Closed
james-d-mitchell opened this issue Feb 5, 2020 · 4 comments
Closed

Copying large digraphs is slow #292

james-d-mitchell opened this issue Feb 5, 2020 · 4 comments
Assignees
Labels
good-second-issue A label for issues that are good second time contributors performance A label for issues or PR related to performance resolved-pending-release A label for issues that have been resolved and that can be closed when a new version is released.

Comments

@james-d-mitchell
Copy link
Member

While working on something, @mariatsalakou and I noticed:

gap> D := CycleDigraph(10 * 10 ^ 6);
<immutable cycle digraph with 10000000 vertices>
gap> time;
3268
gap> D := DigraphCopy(D);
<immutable digraph with 10000000 vertices, 10000000 edges>
gap> time;
20714

which is surprisingly slow...

@james-d-mitchell james-d-mitchell added the performance A label for issues or PR related to performance label Feb 5, 2020
@wilfwilson
Copy link
Collaborator

gap> D := CycleDigraph(10 * 10 ^ 6);; time;
910

DigraphCopy in this instance is doing DigraphImmutableCopy, which does the following three things:

gap> copy := ConvertToImmutableDigraphNC( OutNeighboursMutableCopy( D ) );; time;
1072
gap> SetDigraphVertexLabels( copy, StructuralCopy( DigraphVertexLabels( D ) ) );; time;
2
gap> SetDigraphEdgeLabelsNC( copy, StructuralCopy( DigraphEdgeLabelsNC( D ) ) );; time;
5090

which we can verify sums up to about the same time that DigraphCopy takes:

gap> D := CycleDigraph(10 * 10 ^ 6);; DigraphCopy(D);; time;
6462

What is the expensive part of this? It's dealing with the edge labels, especially creating the edge labels of the cycle digraph (which are otherwise unset):

gap> D := CycleDigraph(10 * 10 ^ 6);;
gap> el := DigraphEdgeLabelsNC(D);; time;
4276
gap> el := StructuralCopy(el);; time;
418

Perhaps we need some way of a digraph knowing whether its edge labels have ever been set, or if they're just the default. That way, when doing copy operations (or other operations that preserve the edge labels), then we can simply not do anything.

@james-d-mitchell
Copy link
Member Author

Nice analysis. Yes, we should play with the edge labels code, and try to improve this. Important question: how is your computer 3 times faster than mine??

@wilfwilson
Copy link
Collaborator

Maybe I don't have a million browser tabs open in the background?? 😉 No idea though, because I think our computers are roughly the same model.

@james-d-mitchell james-d-mitchell self-assigned this Mar 6, 2020
@james-d-mitchell james-d-mitchell added newcomer-friendly A label for issues that someone thought might be friendly newcomers. good-second-issue A label for issues that are good second time contributors and removed newcomer-friendly A label for issues that someone thought might be friendly newcomers. labels Jul 15, 2020
@MTWhyte MTWhyte linked a pull request Jul 29, 2020 that will close this issue
@samanthaharper samanthaharper self-assigned this Jul 29, 2020
@MTWhyte MTWhyte removed a link to a pull request Aug 12, 2020
@james-d-mitchell james-d-mitchell added the resolved-pending-release A label for issues that have been resolved and that can be closed when a new version is released. label Nov 18, 2020
@james-d-mitchell
Copy link
Member Author

Resolved in v1.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good-second-issue A label for issues that are good second time contributors performance A label for issues or PR related to performance resolved-pending-release A label for issues that have been resolved and that can be closed when a new version is released.
Projects
None yet
Development

No branches or pull requests

4 participants