-
Notifications
You must be signed in to change notification settings - Fork 89
Improve performance for half-edge construction from <:Connectivity
vector
#1183
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
base: master
Are you sure you want to change the base?
Improve performance for half-edge construction from <:Connectivity
vector
#1183
Conversation
557ad85
to
8f3685c
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1183 +/- ##
==========================================
+ Coverage 88.13% 88.32% +0.18%
==========================================
Files 196 196
Lines 6084 6097 +13
==========================================
+ Hits 5362 5385 +23
+ Misses 722 712 -10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Hi @halleysfifthinc ! Thank you for trying to improve the performance of this constructor. That is super welcome.
Could you please comment on the need to enforce type annotations? Do they really contribute to the performance gains you are seeing? If we could avoid type annotations as much as possible, that would be ideal.
I left some review comments in a first round of review. Happy to review the other parts of the code later.
The type-annotations were added based on investigation with Cthulhu.jl. The type-annotations benefit the later code by allowing the compiler to work with more specific types1. Justification for each annotation given in the review comments. In Blender, I created a test mesh (torus, 72 quads), and the benchmarks vs no type annotations is: All quads, no type-annots benchmark
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
Range (min … max): 626.260 μs … 32.464 ms ┊ GC (min … max): 0.00% … 97.20%
Time (median): 674.720 μs ┊ GC (median): 0.00%
Time (mean ± σ): 762.418 μs ± 731.223 μs ┊ GC (mean ± σ): 7.88% ± 8.53%
▃▅▇██▇▆▅▅▄▄▃▂▂▂▁▁▁ ▁▃▄▃▂▁▁▁ ▂
███████████████████████▇████████████▇▆▄▆▅▅▅▆▅▆▄▆▄▅▃▅▃▅▅▅▃▆▅▆▃ █
626 μs Histogram: log(frequency) by time 1.11 ms <
Memory estimate: 573.52 KiB, allocs estimate: 14665. BenchmarkTools.TrialJudgement:
time: +323.22% => regression (5.00% tolerance)
memory: +271.06% => regression (1.00% tolerance) I then split half the quads into tris (36 quads, 72 tris) and got: Quads and tris; no type-annots benchmark
BenchmarkTools.Trial: 7528 samples with 1 evaluation per sample.
Range (min … max): 3.641 ms … 35.721 ms ┊ GC (min … max): 0.00% … 87.22%
Time (median): 3.837 ms ┊ GC (median): 0.00%
Time (mean ± σ): 3.971 ms ± 970.236 μs ┊ GC (mean ± σ): 2.81% ± 7.91%
▆█▆▂ ▂▁ ▁
█████▇██▆▅▆▄▅▅▅▄▄▁▄▃▄▅▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▆▆▇ █
3.64 ms Histogram: log(frequency) by time 10.7 ms <
Memory estimate: 1.32 MiB, allocs estimate: 39578. BenchmarkTools.TrialJudgement:
time: +348.65% => regression (5.00% tolerance)
memory: +216.15% => regression (1.00% tolerance) Footnotes
|
95e58e9
to
9c37f94
Compare
That is very nice. Could you please share a MWE so that I can reproduce benchmark results and test the PR locally? :) |
Quads and mixed faces meshes here. using Meshes, GeoIO, BenchmarkTools
quads = GeoIO.load("quads.obj").geometry
quads_tris = GeoIO.load("quads_tris.obj").geometry
@benchmark topoconvert(HalfEdgeTopology, quads)
@benchmark topoconvert(HalfEdgeTopology, quads_tris)
|
1d9cf83
to
71a2312
Compare
I reimplemented Along the way, I found a weird mesh/topo that is manifold, however, the old |
Failed CI doesn't seem related. |
@halleysfifthinc thank you for refactoring the code. I refactored it a bit more to make sure the new algorithm is easy to read. Do we still need to reintroduce type annotations to improve performance? Appreciate it if you could take another look. If type annotations are necessary, we could start with annotating the return type of If we could encapsulate these type annotations in the |
Do you mean that the old implementation had a bug? Is it present in the new implementation in this PR? |
7802cbb
to
2b1d8a2
Compare
Just pushed yet another refactor, this version is much faster still (and as an unintentional bonus, now actually properly separates connected components, which as previously discussed, is something I need). I converted to a draft, as I am still unsatisfied with some behaviors, but can't continue spending time on this for the moment. I will update the benchmarks when I get a chance. |
That is really amazing @halleysfifthinc. The new connected components function is quite useful in other contexts. We should probably convert it to a utility function after this PR is merged. Looking forward to it! |
Benchmarks updated (now specifically for Re:
Yes, the old However, the old Meshes.jl/src/topologies/halfedge.jl Lines 177 to 182 in 28c7555
Footnotes
|
🚀 Please let us know when the PR is ready for review @halleysfifthinc 🙂 |
Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
…or common polygons (tris and quads)
2b1d8a2
to
a366378
Compare
Thank you for the update @halleysfifthinc. Before I spend time reviewing the minor details in the diff, could you please confirm the nature of the changes in this PR? Is it correct to say that there are
and nothing else? What about the behavior change you mentioned? Where is it coming from? You mean that the new I wonder if we could split this PR into smaller PRs that are easier to review and test. The |
Yes that is a correct summary. I'm happy to split this up for easier review if you would like.
Yes, the new
The old definition was theoretically defined by >2 previously observed vertices, but due to the way I won't have the time to investigate the new test failures for a few days. |
That would be super appreciated. Smaller PRs with all tests passing can be quickly merged and shared with all users of the package via patch releases. If you can identify subsets of changes that just improve performance, without behavior change, we can quickly review and approve. |
Using a 72 tri, 36 quad torus, I measure the following speed and memory improvements with BenchmarkTools:
Benchmarking setup
Using the two meshes from this gist.
adjsort
masteradjsortperm
PRJudgement:
Using a 72 quad torus, I see
adjsort
masteradjsortperm
PR