-
Notifications
You must be signed in to change notification settings - Fork 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
Use arrays rather than Dicts for Contour Chasing #51
base: master
Are you sure you want to change the base?
Conversation
…culation The chief suspect in allocation (and triggering GC) was all the small arrays allocated to handle ambiguous cases. With this solution we use the 5th bit (0x10) to indicate an ambiguous case. The logic to disambiguate is handled in the processing of crossings. This significantly reduces memory allocations and yields modest performance improvements.
This reverts commit 6e2b878.
This reverts commit b1a9150.
src/Contour.jl
Outdated
@@ -187,6 +197,7 @@ end | |||
|
|||
# Maps cell type to crossing types for non-ambiguous cells | |||
const edge_LUT = (SW, SE, EW, NE, 0x0, NS, NW, NW, NS, 0x0, NE, EW, SE, SW) | |||
const start_edge_LUT = (0x00, 0x00, 0x01, 0x00, 0x01, 0x02, 0x00, 0x00, 0x01, 0x02, 0x00, 0x04, 0x00, 0x00) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these should probably be refactored to use some name constants instead of just magic numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for looking at this. I agree. Even better, on the latest diff these aren't there at all.
I was playing around with collapsing the branching logic but it turns out that the codegen was the same since Julia inlined and LLVM unrolled the loops and merged everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I haven't actually spent any time with this codebase for several years, so someone else should probably review it too. That's why I left it as a flat comment, without either 👍 or 👎 - I want to leave the actual decision to someone else... :)
Here is a case where allocations are greater but performance is better:
Master:
PR:
#50 :
|
This builds on #50. Inspired by: https://www.researchgate.net/publication/282975362_Flying_Edges_A_High-Performance_Scalable_Isocontouring_Algorithm
This could serve as a basis for that implementation, which should yield even better performance once fully implemented.
The basic idea is to store each case in a 2D Matrix and loop through this matrix (once). Since the matrix is all UInt8, it ends up very compact in memory. We also avoid hashing overhead and do not need to store keys. Since we track the number of non-zero elements for large arrays, sparse contours (such as one closed loop) should still perform better than the dictionary approach, though they may require more memory allocations.
For reference:
v0.5.1:
This PR: