-
Notifications
You must be signed in to change notification settings - Fork 421
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
Fixing memory leaks and reducing memory usage with unique_ptr #666
base: master
Are you sure you want to change the base?
Conversation
…e_ptr Fixing memory leaks and reducing memory usage by switching to a unique_ptr
I have no idea why it doesn't pass the checks, it works perfectly fine for me... |
Fixed the issue that prevented to pass the test. |
I'm sorry for the slow follow-up here. I finally got around to testing your change using the three benchmarks. Here are my results (all benchmark values are in milliseconds):
As you can see, there's a good improvement when using your code in saving a large file (5.6s -> 4.2s), but it comes at the cost of slower style/format creation. Formats are large data structures so I guess there's some optimization being lost switching to unique_ptr. As it stands, I like that the code is cleaner, but it doesn't seem to have a large overall performance impact in either direction. Do you know if there were memory leaks caused by the optional class as it was? One final note is that This isn't totally related to the PR, but I'm also curious about the possibility of using some more battle-tested header-only optional implementations such as https://github.com/martinmoene/optional-lite or https://github.com/TartanLlama/optional/pulls. These mostly follow the C++17 optional API and would simplify a future migration. |
Thank you for the benchmark, very interesting! I believe there were memory leaks caused by the optional class as it was. When trying to load very large files (160MB with 800,000 rows x 80 columns, filled with doubles), the program takes forever to load, using more and more memory until it crashes, thus failing to load the file. I have 16GB of RAM on my computer. When switching to smart pointers, the progam was able to load my file. I believe the possibility to open very large files outweigh the possible loss of a few milliseconds on style/format creation, in my view. The other reason I did this is that switching to shared pointers in the future could further decrease memory usage when files contain duplicate data which could be grouped under a shared pointer. |
Fixing memory leaks and reducing memory usage by switching to a unique_ptr. This helps improves performance as discussed in issue #648.