nalgebra icon indicating copy to clipboard operation
nalgebra copied to clipboard

Proposal: Agressively feature gate parts of the code as a way to make compiling faster

Open arturoc opened this issue 3 years ago • 1 comments

Compiling nalgebra is usually quite slow, mostly because of it's extensive use of generics but also given how large it's code base is.

On the other side when using nalgebra for purposes like graphics math most of it's features are rarely used and only a small subset is usually needed. I guess for other purposes other similarly small parts of it are used.

Having most of the code except for the very basics disabled by default and adding several features that enable the parts needed for common use cases would surely speed up compiling to a great degree in those cases where only a small subset of nalgebra is needed.

Perhaps a crate to take as reference as it does something similar is syn.

arturoc avatar Jul 24 '22 09:07 arturoc

I’m not sure there is so many elements we can move behind features. Perhaps having a feature for the matrix decomposition and a feature for the geometric transformations could be feasible. But I doubt this will have a significant impact on compilation times considering than the largest and most complex part of the code-base are in the matrix/vector definitions and operations which are needed by all the features of nalgebra. I’m also not a big fan of having many features (and nalgebra already has a bunch) as it complicates the docs, the code (with #[cfg(feature)] everywhere), lowering its readability/maintainability.

As far as compilation times is concerned, things are being improved significantly (https://nnethercote.github.io/2022/07/20/how-to-speed-up-the-rust-compiler-in-july-2022.html) and will continue to improve as the language evolves (with better support of const-generics, and with specialization) to reduce the complexity of our generics drastically.

So, moving matrix decomposition and geometric transformation behind two features may be a viable solution if it ends up actually lowering computation times. But having very fine-grained features like in syn would hurt maintainability and ergonomics too much in my opinion.

sebcrozet avatar Jul 24 '22 15:07 sebcrozet