-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Reducing Build Weight with Drake as an External Dependency #21868
Comments
The first step towards VTK independence for MultibodyPlant #21869 is out. |
A low hanging fruit is to parse glb files. With tiny_gltf it's just a matter of calling a different function: But I see that |
Big picture, I believe the shape of this request is for drake/tools/BUILD.bazel to offer more unsupported flags (i.e., flags not covered by CI) which opt-out of default features, akin to these existing flags already offered there:
In principle that's fine, and we're open to pull requests that implement any flags of interest to downstream bazel users. As with all not-covered-by-CI code, the requirement is that it doesn't "pollute" the codebase overly much, or sow overly much confusion or doubt for everyday Drake Developers to make progress. In other words, unsupported flags must not get in the way of the supported code and features. For Also note that the |
I agree, a few more unsupported feature flags would be nice. Do you think some minimal CI would be useful? Perhaps |
I’ve also noticed that we have quite a few source files with unused headers and build dependencies. What are your thoughts on incorporating tools like clang_tidy, include-what-you-use, or cppclean, etc.? For build dependencies, I know there’s some nice tooling for java + buildozer, but I couldn’t find anything equivalent for C++. |
The thing we want to avoid is any increase the permutation count of CI jobs (https://drake-jenkins.csail.mit.edu/view/Production/). The permutations cover the basics like different operating systems and debug vs release, but in terms of this issue the relevant permutation option is whether the dependency footprint is "default" (which has no special mention in the CI job name) or else the "everything" CI variant which has all of the optional dependencies enabled (Gurobi, Mosek, OpenMP, OpenUSD, Snopt, etc.). We don't want to add for example a "minimal" CI variant, because of all of the extra CI jobs and babysitting it would need. On the other hand, if it's possible to add new unit tests (ala the no-spdlog test flavor) to help lock in certain flags, those kinds of things are plausible. It just depends on the "not get in the way too much" metric upthread.
For IWYU in particular, my baseline is that the time investment required to configure it correctly to avoid too many false positives and false negatives on a project of this size is more costly than its benefit. For clang-tidy, my experience several years ago was that the latency of running it was too high to be enabled by default, but maybe its faster now. I don't know cppclean at all. In general the idea is that we are open to new linters that make life better, but someone would need to sit down and do all of the prep work and configuration fine-tuning so that developers are not impacted by false results, and understand how to use the new tooling. |
On the subject of VTK dependency. While removing VTK from various sites now holds certain appeal, it has been mooted in the past that we'd use VTK's broader file support to allow Drake to support more file formats (e.g., .stl, .dae, etc.) So, killing VTK from one particular compilation unit may be undone by something more fundamental in the future. |
I agree that clang-tidy can be extremely slow if configured too broadly, which may explain why I have seen split configurations into fast and slow. Nevertheless, I do like that bazel_clang_tidy comes with caching enabled, which worked quite well on my machine. However, it's a bummer that
From my understanding we only parse .vtk, .obj and .gtlf files to compute convex hulls and don't leverage VTK there fully. I'd be in favor for a lightweight dependency parsing more file types consistently across drake. |
This isn't a downside problem for Drake proper, though, which is why we haven't focused on trying to be more precise. Drake as a whole uses a wide baseline of dependencies, all privately vendored into
As of today, yes. However, we will eventually (hopefully soon) add In general, our metrics for choosing dependencies is getting the job done easily and correctly via a well-maintained external that we can trust. Minimizing the build footprint is not particularly high on the list. |
I see your point, although with the drake-external-examples my impression was that there are supported workflows building from source and not referencing |
That's true, static linking a subset using Bazel is supported. I guess I would amend my statement then to say that I haven't seen examples of enough spurious dependencies edges to cause any meaningful pain for that use case, so we haven't prioritized trying to be formally precise with a linter. The easiest solution might just be to fix spurious things that crop up and cause acute pain, but without any linting backstop. I don't imagine that spurious deps will grow back very fast. |
FYI In my PR train for #20731, I already have a WIP branch that starts to switch away from |
#22393 is the beginning of Stable API flags to turn on/off dependencies. For now it's just the solvers. After a few others things merge first, then the eigen+fmt+spdlog flags will appear (to toggle whether they come from BCR or pkg-config, and to allow opt-out of spdlog). After that I hope to add support for pulling zlib, glib, etc. from BCR instead of pkg-config, so that Drake can hermetically build on any modern platform. I should probably also promote our flag to opt-out of Java (for LCM) to be a Stable API flag. Following the pattern of #22393, developers interested in this ticket could offer PRs with more option flags. For example, we could have flags to opt-out of the There could also be a flag to opt-out of having Drake's There could also be an official flag to opt-of of Meshcat, which might help us build on platforms where the websockets server can't even compile. That would require some refactoring though, so that we can easily replace Meshcat's function bodies with something that throws (like we do for the solvers). I think the refactoring required for #20889 to better encapsulate the implementation would probably make that easier. |
Awesome, thank you for setting up a good path forward @jwnimmer-tri ! I am excluding a lot and trying to exclude even more. I hope to only remain with these dependencies (or even less!):
|
Whenever we deprecate support for consuming Drake as a WORKSPACE external (per #20731), the whole Or, if you're patching Drake and building it first-party instead of consuming it as an external, then see the pending #22338 which changes how Drake declares its dependencies. I imagine a patch should be able to delete lines from the MODULE file equally as easy as it was to tweak the WORKSPACE flavor. |
I see, so with the bzlmod completion I could help in adding a few opt-out flags that make sense for the wider community and the rest could be handled by patching the MODULE file. |
Drake comes with a strong ecosystem, but similar to the solvers there are parts of drake that could be lighter and optionally excluded in the build. Note that this is specific for drake as an external dependency. I hope we can strategize in this issue an approach and where we can drop baggage.
Here are a few heavy things that I think could be excluded. Feel free to suggest more!
Default Assets:
While going through
package_map
, I found that find_resources has a few steps to look for assets, default paths, libmarker.so, etc. Maybe some steps could be excluded with a flag?Meshcat:
Meshcat is great, but there are various applications of drake that don't require visualization. From my understanding, this is pretty easy to exclude. We just don't reference meshcat and excluded it via add_default_workspace ✅
Renderers:
I was stunned to find out that just building
MultibodyPlant
pulls in vtk_internals, then X11, OpenGL, GLX to parse VTK meshes and glTFs. Would it be possible to make VTK mesh parsing optional and switch to tinyglTF (which also supports glb) files? That way, we can avoid pulling in the whole rendering pipeline. Obviously, I have to look at more corners to see where VTK is used other than for rendering.Spdlog
This is one is interesting. There are flags that check for HAVE_SPDLOG. The only way to exclude it is to create an empty spdlog target which doesn't ship the HAVE_SPDLOG flag. Maybe there could be a more developer friendly and documented approach?
The text was updated successfully, but these errors were encountered: