8000 Fix memory leak by pca006132 · Pull Request #280 · elalish/manifold · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix memory leak #280

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

Merged
merged 7 commits into from
Nov 17, 2022
Merged

Fix memory leak #280

merged 7 commits into from
Nov 17, 2022

Conversation

pca006132
Copy link
Collaborator

Fix #245. Not yet tested to see if it works on the particular example, but I think this should solve the root issue. The meshids is a rough estimate of the number of distinct mesh ids in the mesh, so we can initialize the hash table with large enough size and avoid many collision which will slow down the performance (especially when using CUDA because of warp divergent).

The original hashtable is modified to accept any value type. The key is
still uint64 because atomic is impossible for general key type, and it
seems that we don't really need the key to be generic.
A "better" hash function is added to replace the original identity hash
function, which should hopefully give less collision, seems doing
nothing for now because our test cases don't have much collision.
@pca006132 pca006132 requested a review from elalish November 11, 2022 18:47
@pca006132
Copy link
Collaborator Author

btw @elalish I am not sure why the step for hashtable is set to 127 by default. It seems that if we are using linear probing we should use 1?

@codecov-commenter
Copy link
codecov-commenter commented Nov 12, 2022

Codecov Report

Base: 91.39% // Head: 91.37% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (0601455) compared to base (98a61df).
Patch coverage: 88.52% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #280      +/-   ##
==========================================
- Coverage   91.39%   91.37%   -0.02%     
==========================================
  Files          32       33       +1     
  Lines        3474     3490      +16     
==========================================
+ Hits         3175     3189      +14     
- Misses        299      301       +2     
Impacted Files Coverage Δ
src/manifold/src/impl.h 83.33% <ø> (ø)
src/utilities/include/hashtable.h 83.78% <83.78%> (ø)
src/manifold/src/impl.cpp 93.39% <93.33%> (+0.44%) ⬆️
src/manifold/src/boolean_result.cpp 97.93% <100.00%> (+<0.01%) ⬆️
src/manifold/src/csg_tree.cpp 93.98% <100.00%> (+0.05%) ⬆️
src/sdf/include/sdf.h 98.64% <100.00%> (+1.47%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Owner
@elalish elalish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's late and I haven't managed to read through this properly yet, but the main actionable thing is to make the hash function take another input so it can be used in its original form too. Thanks!

inclusive_scan(
autoPolicy(meshidTable.Size()), meshidTable.GetValueStore().begin(),
meshidTable.GetValueStore().end(), meshidTable.GetValueStore().begin());
const int numMeshIDs = meshidTable.GetValueStore().back();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you just want the number of hash table entires, can you just call Entries()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah true!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh it doesn't work, because every value in the map will be 1.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If every value in the map is 1, why do we need a hash table? Have you tested this against the original bug repro? What is the amount of speed up? This sort of looks like it's doing even more work than the vector version, but maybe I'm missing something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem in the original issue is that, the vector being allocated has size the global mesh id counter, which can be very large even when the mesh object itself only consists of a few mesh ids. A hash table is used so we can ignore those meshids that are not present in the current mesh.
For performance, I did not measure it against the ols version. It may be a bit slower in general, but as the global counter keep increasing, it will eventually become faster than the original one and uses less memory.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thank you, I missed what meshids was doing. Now that this is a hash table, is this scan to remove orphaned meshIDs useful anymore? I'm thinking in context of #282 and #218, that we could hit two birds with one stone by saving the transforms associated with each meshID. However, especially for #218, it would be important to keep them all rather than removing ones that don't contribute triangles.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the scan by using the hash table index as some unique ID for each mesh id, although I am not sure how much of a difference can this make. And this will require a slightly different API. (get raw index or something)
This is probably not related to saving transforms because the hash table is just temporary, we need another thing to store them.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I forgot we were also using the scan to assign new ids. Thanks!

Copy link
Owner
@elalish elalish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is looking just about ready. Time to update the branch?

inclusive_scan(
autoPolicy(meshidTable.Size()), meshidTable.GetValueStore().begin(),
meshidTable.GetValueStore().end(), meshidTable.GetValueStore().begin());
const int numMeshIDs = meshidTable.GetValueStore().back();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thank you, I missed what meshids was doing. Now that this is a hash table, is this scan to remove orphaned meshIDs useful anymore? I'm thinking in context of #282 and #218, that we could hit two birds with one stone by saving the transforms associated with each meshID. However, especially for #218, it would be important to keep them all rather than removing ones that don't contribute triangles.

Copy link
Owner
@elalish elalish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@elalish elalish merged commit 8705950 into elalish:master Nov 17, 2022
@elalish elalish mentioned this pull request Feb 20, 2023
@pca006132 pca006132 deleted the fix-memory-leak branch August 15, 2023 12:54
cartesian-theatrics pushed a commit to cartesian-theatrics/manifold that referenced this pull request Mar 11, 2024
* generic hashtable implementation

The original hashtable is modified to accept any value type. The key is
still uint64 because atomic is impossible for general key type, and it
seems that we don't really need the key to be generic.
A "better" hash function is added to replace the original identity hash
function, which should hopefully give less collision, seems doing
nothing for now because our test cases don't have much collision.

* fix elalish#245

* fixed uninitialized field

* change hashtable probe step

* put hash function in template parameter

* fixed compiler error

Co-authored-by: Emmett Lalish <elalish@gmail.com>
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

Successfully merging this pull request may close these issues.

Memory leak problem
3 participants
0