elastic / elasticsearch-rs

Official Elasticsearch Rust Client
https://www.elastic.co/guide/en/elasticsearch/client/rust-api/current/index.html
Apache License 2.0
695 stars 70 forks source link

[Experiment] Use a Cargo feature for each namespace to reduce compilation time and binary size #141

Closed swallez closed 3 years ago

swallez commented 3 years ago

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:

[dependencies]
elasticsearch = { path = "../elasticsearch", default-features = false, features = ["native-tls", "async_search"]}

This PR is organized in 3 commits:

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.