Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Memory Improvement #13

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

Open
rschio wants to merge 15 commits into yourbasic:master
base: master
Choose a base branch
Loading
from rschio:v2
Open

Memory Improvement #13

rschio wants to merge 15 commits into yourbasic:master from rschio:v2

Conversation

@rschio
Copy link

@rschio rschio commented Oct 21, 2022

This PR contain memory improvements to the following functions:

  • Acyclic
  • BFS
  • Bipartition
  • Components
  • Connected
  • EulerDirected
  • EulerUndirected
  • MST
  • ShortestPath
  • ShortestPaths
  • Sort
  • TopSort
  • Transpose

The technique to use less memory is equal in all the functions. I declared the closures (from g.Visit(v, closure)) outside the loop (related: #8), the result is the closure is allocated only one time and not allocated in each loop iteration.

I changed ShortestPath to stop when finding the target vertex.

I added the benchmark results in the testdata directory (it can be removed). The benchmarks were done in my machine with background processes running so the speed results aren't very reliable, but the memory results should be.

Obs: I didn't change the StrongComponents because it uses a recursive function, so the technique didn't fit well, and I didn't change MaxFlow because the improvement in memory was tiny.

Benchmark Results:

name old time/op new time/op delta
Acyclic-8 128μs ± 0% 66μs ± 0% -47.95%
name old alloc/op new alloc/op delta
Acyclic-8 52.0kB ± 0% 12.4kB ± 0% -76.18%
name old allocs/op new allocs/op delta
Acyclic-8 1.17k ± 0% 0.01k ± 0% -98.89%
name old time/op new time/op delta
BFS-8 269μs ± 0% 206μs ± 0% -23.36%
name old alloc/op new alloc/op delta
BFS-8 86.8kB ± 0% 23.2kB ± 0% -73.27%
name old allocs/op new allocs/op delta
BFS-8 1.01k ± 0% 0.02k ± 0% -98.33%
name old time/op new time/op delta
Bipartition-8 1.88μs ± 0% 1.40μs ± 0% -25.44%
name old alloc/op new alloc/op delta
Bipartition-8 3.62kB ± 0% 2.79kB ± 0% -22.79%
name old allocs/op new allocs/op delta
Bipartition-8 26.0 ± 0% 14.0 ± 0% -46.15%
name old time/op new time/op delta
Components-8 196μs ± 0% 149μs ± 0% -24.01%
name old alloc/op new alloc/op delta
Components-8 86.8kB ± 0% 54.8kB ± 0% -36.83%
name old allocs/op new allocs/op delta
Components-8 1.23k ± 0% 0.23k ± 0% -80.96%
name old time/op new time/op delta
Connected-8 151μs ± 0% 104μs ± 0% -31.26%
name old alloc/op new alloc/op delta
Connected-8 40.2kB ± 0% 8.3kB ± 0% -79.45%
name old allocs/op new allocs/op delta
Connected-8 1.00k ± 0% 0.01k ± 0% -99.50%
name old time/op new time/op delta
EulerDirected-8 7.28μs ± 0% 2.00μs ± 0% -72.44%
name old alloc/op new alloc/op delta
EulerDirected-8 5.71kB ± 0% 0.96kB ± 0% -83.19%
name old allocs/op new allocs/op delta
EulerDirected-8 103 ± 0% 4 ± 0% -96.12%
name old time/op new time/op delta
EulerUndirected-8 7.07μs ± 0% 2.39μs ± 0% -66.21%
name old alloc/op new alloc/op delta
EulerUndirected-8 5.72kB ± 0% 0.97kB ± 0% -83.08%
name old allocs/op new allocs/op delta
EulerUndirected-8 104 ± 0% 5 ± 0% -95.19%
name old time/op new time/op delta
MST-8 249μs ± 0% 190μs ± 0% -23.85%
name old alloc/op new alloc/op delta
MST-8 96.9kB ± 0% 33.0kB ± 0% -65.99%
name old allocs/op new allocs/op delta
MST-8 1.01k ± 0% 0.01k ± 0% -99.20%
name old time/op new time/op delta
ShortestPath-8 141μs ± 0% 60μs ± 0% -57.23%
name old alloc/op new alloc/op delta
ShortestPath-8 79.9kB ± 0% 39.8kB ± 0% -50.23%
name old allocs/op new allocs/op delta
ShortestPath-8 856 ± 0% 21 ± 0% -97.55%
name old time/op new time/op delta
ShortestPaths-8 121μs ± 0% 80μs ± 0% -34.06%
name old alloc/op new alloc/op delta
ShortestPaths-8 79.2kB ± 0% 39.7kB ± 0% -49.85%
name old allocs/op new allocs/op delta
ShortestPaths-8 841 ± 0% 19 ± 0% -97.74%
name old time/op new time/op delta
Sort-8 608μs ± 0% 500μs ± 0% -17.79%
name old alloc/op new alloc/op delta
Sort-8 249kB ± 0% 201kB ± 0% -19.25%
name old allocs/op new allocs/op delta
Sort-8 6.03k ± 0% 5.03k ± 0% -16.57%
name old time/op new time/op delta
TopSort-8 135μs ± 0% 69μs ± 0% -48.49%
name old alloc/op new alloc/op delta
TopSort-8 56.1kB ± 0% 16.5kB ± 0% -70.62%
name old allocs/op new allocs/op delta
TopSort-8 1.18k ± 0% 0.02k ± 0% -98.14%

name old time/op new time/op delta
Transpose-8 404μs ± 0% 401μs ± 0% -0.72%
name old alloc/op new alloc/op delta
Transpose-8 218kB ± 0% 170kB ± 0% -22.04%
name old allocs/op new allocs/op delta
Transpose-8 5.00k ± 0% 4.00k ± 0% -19.98%

h6ah4i and davidroman0O reacted with heart emoji davidroman0O reacted with rocket emoji
rschio added 15 commits October 20, 2022 16:51
Declare the visit closure before the loop.
Declare the closure before the loop.
removes the visit closure from inside the loop.
ShortestPath now stops when the target vertex is found.
This reverts commit 52e36155619719f60a25f20f5aaabd136b59dafd.
This reverts commit 745e29b535c59d8891ff133751c6aa1de3ea1ab2, reversing
changes made to 4ee17fc62955eedb59fc94965463110769791642.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /