sergiimk opened a new pull request, #23767:
URL: https://github.com/apache/datafusion/pull/23767

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax. For example `Closes #123` 
indicates that this PR will close issue #123.
   -->
   
   Closes: #6470
   
   ## Rationale for this change
   
   As we build many tools with `datafusion` we have many dozens of crates in 
our workspace depending on it, and **every test and example** ends up linking 
DF library statically, resulting in:
   - Bloat - DF contributes around 1.2GiB to every executable in `dev` profile, 
linking DF dynamically reduces our `dev` build footprint from 112GiB to 57GiB
   - Slow build times - linking DF dynamically reduced link times of some 
executables by 10s.
   
   We believe offering an option for dynamic linking can provide a good 
productivity boost for local development and shorted interations.
   
   The proposed implementation mirrors [dynamic linking in Bevy 
engine](https://bevy.org/learn/quick-start/getting-started/setup/#dynamic-linking)
 which has provided this option for years for similar reasons. The mechanism is 
**opt-in**, and imposes **zero cost** on consumers who don't enable it.
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is 
sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   This PR proposes a new feature `datafusion/dynamic` which when enabled 
builds a `dylib` for dynamic linking.
   
   ### How it Works
   
     - The existing `datafusion` crate is renamed to `datafusion-core`. The 
package rename is invisible to consumers
     because [lib] name = "datafusion" preserves the import name — all use 
datafusion::... statements in
     downstream code (and in datafusion's own tests, benches, and bins) 
continue to work unchanged.
     - A new `datafusion-dylib` sub-crate is added with `crate-type = 
["dylib"]`. It contains a single `use datafusion_core
      as _;` statement, which is what forces the dynamic library to contain the 
`datafusion-core` symbol table.
     - A new `datafusion` facade crate is introduced that re-exports everything 
from `datafusion-core` and forwards every existing feature 1:1.
     - The facade owns the new dynamic feature, which is off by default. When 
enabled, the facade's pulls in `datafusion-dylib` via `#[cfg(feature = 
"dynamic")] use datafusion_dylib as _;`
     - Linker sees duplicated symbols and automatically prefers those from a 
shared library.
   
     Dependency graph:
   
   ```
                            ┌────────────────┐
                            │   datafusion   │  ← facade (unchanged public name 
& API)
                            │    (facade)    │     owns the `dynamic` feature
                            └───────┬────────┘
                                    │
                          pub use ::datafusion::*
                                    │
                         ┌──────────┴──────────┐
                         │                     │
                         │  (always)           │  (only when `dynamic` feature 
is on)
                         │                     │
                         ▼                     ▼
               ┌─────────────────┐   ┌──────────────────┐
               │ datafusion-core │   │ datafusion-dylib │
               │  (renamed from  │   │  crate-type =    │
               │   datafusion)   │   │     ["dylib"]    │
               │                 │   │                  │
               │                 │   │  use datafusion  │
               │                 │◄──┤       as _;      │
               │  all real code  │   │                  │
               └─────────────────┘   └──────────────────┘
   ```
   
   When `dynamic` feature is off (default), `datafusion-dylib` is not compiled 
at all — no cost.
   
   ### Downsides & Limitations
   - All feature flags need to be propagated 1:1 from the facade into the core 
crate adding slight maintenance burden
   - Current PR uses `[lib] name = "datafusion"` on core crate which can cause 
confusion with the facade crate. This is only to keep `use datafusion::*` 
inside the `datafusion-core` crate working unchanged. Full PR should probably 
change those statements to `use crate::*`.
   
   ## Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they covered by existing tests)?
   -->
   
   We have tested it in our builds against a fork, but more tweaks may be 
necessary for different target platforms (e.g. wasm).
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api 
change` label.
   -->
   
   No. The new facade library should be fully substitutable for the original 
one.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to