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

Performance of make_basic_network #913

Closed
mtanneau opened this issue Jun 11, 2024 · 3 comments
Closed

Performance of make_basic_network #913

mtanneau opened this issue Jun 11, 2024 · 3 comments

Comments

@mtanneau
Copy link
Contributor

mtanneau commented Jun 11, 2024

The make_basic_network function is slow for large networks.
The timings below were obtained with @time make_basic_network(data) where data was loaded with the PGLib package.

Case #buses time (s) memory (MiB)
1354_pegase 1354 0.21 28.5
2869_pegase 2869 0.62 66.8
9241_pegase 9241 2.50 208.4
13659_pegase 13659 5.72 303.1
30000_goc 30000 15.81 467.8

I profiled it on the 9241_pegase case:
prof_old

which shows that, besides an initial deepcopy which we can't do much about, a substantial amount of time is spent identifying connected components.
Note that the very high stacktrace with _cc_dfs corresponds to recursive calls to a DFS implementation here.

PR coming

@mtanneau
Copy link
Contributor Author

@ccoffrin I have opened two PRs to address the initial deepcopy (#915) and the identification of connected components (#914).

The 3rd room for performance improvement is within _renumber_components, which contains a lot of deepcopys itself.
Namely, all individual components are deepcopied before being re-numbered.

I believe this is not necessary, since we deepcopy the initial data dictionary, and everything afterwards modifies the data dict in-place. As far as I can see, _renumber_components is only called inside make_basic_network, so eliminating the deepcopy below would save further time and memory

for (i,comp) in enumerate(comp_ordered)
comp = deepcopy(comp)
comp["index"] = i
renumbered_dict["$i"] = comp
end

@ccoffrin
Copy link
Member

ccoffrin commented Jul 6, 2024

Has this been addressed by #919?

@mtanneau
Copy link
Contributor Author

mtanneau commented Jul 8, 2024

Yes!

For completeness, I re-ran the timings and profiles on master; results are below.


New timing table on master for make_basic_network:

Case #buses time (s) memory (MiB)
1354_pegase 1354 0.13 20.1
2869_pegase 2869 0.29 45.7
9241_pegase 9241 1.09 137.1
13659_pegase 13659 1.47 215.5
30000_goc 30000 2.53 320.1

and corresponding profile on 9k Pegase system
prof_master


Same, but for the in-place make_basic_network!:

Case #buses time (s) memory (MiB)
1354_pegase 1354 0.05 11.0
2869_pegase 2869 0.13 27.2
9241_pegase 9241 0.47 74.7
13659_pegase 13659 0.70 130.0
30000_goc 30000 1.27 181.6

and corresponding profile on 9k Pegase system

prof_master

@mtanneau mtanneau closed this as completed Jul 8, 2024
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

No branches or pull requests

2 participants