-
Notifications
You must be signed in to change notification settings - Fork 216
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
Fix performance issues for vector-based storage #413
Fix performance issues for vector-based storage #413
Conversation
228df65
to
836919b
Compare
Thanks for your pull request.
Yup, that's good.
I don't actually see why this is so, unless |
Everything I'm writing here assumes that TLDR: Calling Now, for the long and windy explanation. Inside
and
I.e. in case the new size is larger than the old, Note that it clearly states that the complexity is linear, not O(1). Growing an Manually calling
I did not see existing performance benchmarks, so I didn't try to implement one. However, the behavior of calling Here is a quick benchmark I threw together illustrating the difference: quick-bench. Note that the difference is only 10% here, most likely because there's not that much data to copy around. I tried creating another benchmark where each entry in the vector is larger (which would be the case when e.g. a vertex has bundled properties that take up a reasonable amount of space). Unfortunately the quick-bench.com website kept timing out on that. I expect the difference to be much more pronounced in this case. If you'd like to try yourself, here's the code in Compiler Explorer (you can hit "Quick bench" in the top left there). Edit: I realize the benchmarks show only a small speed difference. I guess the compiler somehow sees through the whole thing? I know of instances in industrial code where this exact same change caused a massive speed-up. |
Here's another snippet from
|
836919b
to
ebe6a6e
Compare
ebe6a6e
to
15b587a
Compare
Ohh, I get it, sorry, I just completely forgot that |
Thanks for a great improvement to the efficiency! I know the code change was very small, but in future please don't combine unrelated changes into one PR. |
Thanks a lot for the quick merge! I'll try to better pay attention to the PR hygiene next time 😁. |
vertex_by_property()
required a mutable graph object, butvertex_by_property()
itself did. This is now fixed.container.reserve(container.size() + 1)
, e.g.add_vertex()
. Calling such anadd_vertex()
in a loop with anstd::vector
backing the vertex storage results in O(N²) time complexity instead of the expected (amortized) O(N). This is fixed by allowing the container to grow as expected.