This an experiment that didn't prove successful. Adding it as a PR that we can close but keep for posterity and future reference.
This PR creates a Cargo feature for each generated API namespace. The purpose is to allow an application to describe the actual subset of API namespaces it effectively uses, in order to reduce compilation times and/or executable size.
f105514 updates the generator to add #![cfg(feature = "<namespace>" )] at the top of each namespace module to allow conditional compilation and declare the corresponding features in elasticsearch/Cargo.toml.
53e0352 updates the generated code with the above generator change
8806d19 is a small test project to experiment with features
The results:
compilation time: does not change by reducing the list of features. Rustc compiles (at least up to a certain stage) code that is disabled. This can be verified by introducing syntax errors in the code of disabled features: compilation will fail.
executable size: does not change. Looking at the executable's symbol table, we can see that unused modules aren't included in the final binary, even if their corresponding feature is enabled.
A conclusion of this experiment is that Cargo features should really be used to conditionally compile code that depends either on the platform, other crates (e.g. openssl vs rustls) or native libraries. It doesn't change anything for regular code that doesn't pull additional external dependencies.
Another conclusion is that if we want to reduce compilation time (binary size is already optimized) the only solution is to split the Rust client into finer-grained crates (e.g. one per namespace). The effort and resulting release process complexity is probably not worth it as the compilation, even if a bit lengthy, will only happen once.
This an experiment that didn't prove successful. Adding it as a PR that we can close but keep for posterity and future reference.
This PR creates a Cargo feature for each generated API namespace. The purpose is to allow an application to describe the actual subset of API namespaces it effectively uses, in order to reduce compilation times and/or executable size.
An application's
Cargo.toml
could look like this:This PR is organized in 3 commits:
#![cfg(feature = "<namespace>" )]
at the top of each namespace module to allow conditional compilation and declare the corresponding features inelasticsearch/Cargo.toml
.The results:
A conclusion of this experiment is that Cargo features should really be used to conditionally compile code that depends either on the platform, other crates (e.g. openssl vs rustls) or native libraries. It doesn't change anything for regular code that doesn't pull additional external dependencies.
Another conclusion is that if we want to reduce compilation time (binary size is already optimized) the only solution is to split the Rust client into finer-grained crates (e.g. one per namespace). The effort and resulting release process complexity is probably not worth it as the compilation, even if a bit lengthy, will only happen once.