8000 make collider header-only by pca006132 · Pull Request #871 · elalish/manifold · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

make collider header-only #871

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 8 commits into from
Jul 25, 2024
Merged

make collider header-only #871

merged 8 commits into from
Jul 25, 2024

Conversation

pca006132
Copy link
Collaborator

Not very sure about this one, I guess this depends on how far we want to go for optimizing compile time.

I wanted to optimize some collider related performance issue, which requires passing functions inside the collider loop. However, I recall that the reason we put collider into .cpp file instead of using templates in the header function is due to compile time concern, which was pretty painful when we compiled using nvcc. We don't use nvcc now, and I wanted to optimize the build time a bit more so we can have more headroom to make it slower :)

Changes:

  1. Use PCH for expensive headers. Requires minimal changes, reduces compile time slightly:
    • Total: 221s to 190s (enabled virtually everything and does LTO).
    • Minimal total: 93s to 76s (disabled virtually everything)
    • Wall clock time: 17s to 14.6s.
    • Minimal wall clock time: 7.4s to 7.2s.
  2. Enable cmake unity build. This is a pretty invasive change that due to our use of anonymous namespaces. This reduces the total compile time, but wall clock time is slower than typical builds due to less parallelization (clang should try to do parallel codegen...).
    • Total: 115s (cannot directly compare as we did not have unity build before)
    • Minimal total: 38.5s (disabled virtually everything).
    • Wall clock time: 22s.
    • Minimal wall clock time: 13.3s.

@pca006132 pca006132 requested a review from elalish July 21, 2024 17:00
Copy link
codecov bot commented Jul 21, 2024

Codecov Report

Attention: Patch coverage is 92.42424% with 10 lines in your changes missing coverage. Please review.

Project coverage is 90.05%. Comparing base (d437097) to head (d6bfecd).
Report is 65 commits behind head on master.

Files Patch % Lines
src/collider/include/collider.h 92.36% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #871      +/-   ##
==========================================
- Coverage   91.84%   90.05%   -1.79%     
==========================================
  Files          37       64      +27     
  Lines        4976     9161    +4185     
  Branches        0      950     +950     
==========================================
+ Hits         4570     8250    +3680     
- Misses        406      911     +505     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@elalish
Copy link
Owner
elalish commented Jul 21, 2024

Huh, so the total time is the time for each CPU added together? Seems like wall clock time is what we care about, right? So if this is making total time 15% better, but wall clock time 30-50% worse, is that good? You also mentioned making collider into a header - are you still planning to do that? What difference would it make?

I've never heard of a Unity build before, but it looks like it's just concatenating several cpp files for compilation (I sort of thought that would take more, rather than less time, but goes to show how much I know about the compilation process). Still, another reason I like a bunch of separate files is that generally re-compiling is quicker, since I'm often only touching one of those files. How does this change affect re-compilation?

@pca006132
Copy link
Collaborator Author

Yes, total time is the time for each CPU added together. I think it depends on what we are optimizing for, either the developer time or CI time, or both (some devs may have less beefy machines with less cores, idk).

Unity build is not really meant for development, it is for optimizing one-off compilation. And yes, it makes recompilation pretty slow. I did it just because I want to see how much a different it makes, and I am happy to drop that change.

I still plan to make collider into header, will see how it affects compile time. I don't expect there to be a huge increase in compile time because it is still small comparing to things like stl algorithms. We can usually optimize compiler frontend time (parsing) by using PCH. I don't think these functions will be instantiated many times (< 10 across the whole library I think), so backend time should be fine.

@elalish
Copy link
Owner
elalish commented Jul 22, 2024

Okay, that sounds reasonable. Let's see how it looks without the Unity part. I think I'd rather optimize for dev experience than for the CI.

@pca006132
Copy link
Collaborator Author

OK I checked, no measurable compile time difference: 20.2s for header-only collider, 19.5s for the current version.

@pca006132
Copy link
Collaborator Author

And I found that we should not expose collider to users: it uses some of our internal APIs like vec, which are not exposed to users.

@pca006132
Copy link
Collaborator Author

the cmake error can probably be fixed by the build interface thing, will check later tmr

@pca006132 pca006132 changed the title Compile time optimization make collider header-only Jul 24, 2024
@pca006132
Copy link
Collaborator Author

@elalish should we merge this now?

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, looks good!

@pca006132 pca006132 merged commit a93c0c6 into elalish:master Jul 25, 2024
21 checks passed
@pca006132 pca006132 deleted the compile-time branch July 25, 2024 17:30
@elalish elalish mentioned this pull request Nov 5, 2024
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.

2 participants
0