Repository navigation
Datafusion binary size has been getting bigger #13816
Copy link
Copy link
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Is your feature request related to a problem or challenge?
The size of datafusion's binary has grown significantly in the last few releases
This likely leads to higher compile times as well as larger overall binary size
| version | size of datafusion-cli binary |
|---|---|
main at 57d1309 |
92M |
43.0.0 |
87M |
42.0.0 |
83M |
41.0.0 |
72M |
40.0.0 |
69M |
39.0.0 |
68M |
The sizes are measured like this:
git checkout version
cd datafusion-cli
cargo build --release
du -h target/release/datafusion-cliAlso, people such as @g3blv have noticed that the WASM build has increased 50%:
#9834 (comment)
Describe the solution you'd like
I would like to reduce the binary size of DataFusion if possible
At least I would like to understand where the code size comes from and offer hints about how to reduce the size if needed
Describe alternatives you've considered
A common source of code size is templated functions (as that generates multiple copies of the same function(s)).
Here is some fascianting information from running cargo bloat -p datafusion
File .text Size Crate Name
0.1% 0.3% 79.7KiB blake2 blake2::Blake2bVarCore::compress
0.1% 0.2% 70.7KiB blake2 blake2::Blake2sVarCore::compress
0.1% 0.2% 67.1KiB sqlparser <sqlparser::ast::Statement as core::fmt::Display>::fmt
0.1% 0.2% 61.4KiB blake3 _blake3_hash4_neon
0.1% 0.2% 56.4KiB chrono_tz <chrono_tz::timezones::Tz as chrono_tz::timezone_impl::TimeSpans>::timespans
0.1% 0.2% 44.7KiB arrow_cast <i64 as lexical_write_integer::api::ToLexical>::to_lexical
0.1% 0.1% 42.8KiB arrow_cast arrow_cast::cast::cast_with_options
0.0% 0.1% 35.9KiB rand <rand_chacha::chacha::ChaCha12Core as rand_core::block::BlockRngCore>::generate
0.0% 0.1% 34.9KiB arrow_cast lexical_parse_float::slow::parse_mantissa
0.0% 0.1% 33.1KiB arrow_cast lexical_parse_float::parse::parse_complete
0.0% 0.1% 33.1KiB arrow_cast lexical_parse_float::parse::parse_complete
0.0% 0.1% 29.0KiB regex_automata regex_automata::hybrid::search::find_fwd
0.0% 0.1% 27.6KiB blake3 blake3::portable::compress_in_place
0.0% 0.1% 27.1KiB aho_corasick aho_corasick::automaton::try_find_fwd
0.0% 0.1% 25.2KiB sqlparser <sqlparser::ast::Expr as core::fmt::Display>::fmt
0.0% 0.1% 23.8KiB datafusion_common datafusion_common::scalar::ScalarValue::iter_to_array
0.0% 0.1% 23.7KiB datafusion_common datafusion_common::scalar::ScalarValue::iter_to_array
0.0% 0.1% 23.7KiB datafusion_physical_expr datafusion_common::scalar::ScalarValue::iter_to_array
0.0% 0.1% 23.7KiB datafusion_functions_aggregate datafusion_common::scalar::ScalarValue::iter_to_array
0.0% 0.1% 22.0KiB arrow_cast <u64 as lexical_write_integer::api::ToLexical>::to_lexical
36.7% 97.4% 27.7MiB And 139272 smaller methods. Use -n N to show more.
37.7% 100.0% 28.4MiB .text section size, the file size is 75.4MiBAdditional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Activity
comphead commentedon Dec 20, 2024
binaries can be moved out from the main release
comphead commentedon Dec 21, 2024
Some good experiments are https://github.com/johnthagen/min-sized-rust?tab=readme-ov-file#optimize-libstd-with-xargo
with this profile
The cli size went from
94.3MiBdown to48.6MiB🤔alamb commentedon Dec 22, 2024
That is a very cool page 🤔
Omega359 commentedon Dec 23, 2024
Expanding on @comphead's idea adding opt-level = "s" reduced the size of the cli from 52MB on my machine (with his changes) to 37MB.
comphead commentedon Dec 24, 2024
Thanks @Omega359 Opt-level is 3 by default for the release https://doc.rust-lang.org/cargo/reference/profiles.html#release
which focus on maximum runtime speed, I think it is important. However we can strip things to make executable smaller, I'll create a PR soon
alamb commentedon Dec 24, 2024
FWIW I don't think the size of hte datafusion-cli binary is all that critical per se (maybe we can adjust / optimize the size of what is distributed on homebrew)
What I was hoping to review / improve with this PR is the size of the code in general (and review if there were places that were unecessairly causing code bloat that weren't also adding value
alamb commentedon Feb 14, 2025
At a high level, I think this ticket has 2 parts:
I think the most valuable (and hardest) part is 1 (figuring out what to do)
To do so I recommend doing an "Ablation Study"
This is a fancy way of saying "remove parts of the system and see how much impact it makes on binary size"
Suggested things to try
I suggest initially simply trying with different datafusion crate features and see how much extra code each contributes to the binary size.
A follow on idea would be to comment out some of the features that require lots of generic code such as
GroupValues: https://github.com/apache/datafusion/blob/main/datafusion/physical-plan/src/aggregates/group_values/mod.rsGroupAccumulator:datafusion/datafusion/expr-common/src/groups_accumulator.rs
Line 108 in 469f18b
Example of Ablation Study for the
parquetfeatureFor example, to test the impact of the
parquetfeature, I tested the size of the binary with and without parquet supportcargo build --release -p datafusion-cli # get size of datafusion-cli in kb du -k target/release/datafusion-cliHere is what I got
parquetfeatureSo I conclude that the parquet feature adds approximately 5mb to the binary size
To remove parquet support I hacked out the dependency on parquet. Since this was just to test the impact as long as it compiles that is good enough. No need to be pretty. Here is the
comphead commentedon Feb 14, 2025
That is really awesome write up @alamb
Tbh I wanted to do exactly the same but I even had no idea this approach has so smart definition
Ablative Study.alamb commentedon Feb 14, 2025
LOL like most great things I think I first heard this term used in a paper by Viktor Leis and Thomas Neumann
comphead commentedon Feb 21, 2025
btw after changes in 45.0.0 the image size is 49M 🎉
alamb commentedon Feb 23, 2025
Nice! Do you know what changed?
Indeed I checked on my mac after doing
cargo build --releaseand the size is 58MB:andrewlamb@Andrews-MacBook-Pro-2:~/Software/datafusion$ du -s -h target/release/datafusion-cli 58M target/release/datafusion-clicomphead commentedon Feb 23, 2025
Tbh I dont have accurate answer for this, I found it when played with different feature set on latest DF, but I remember some packages were moved out of the core or similar.
Experimenting with different feature set and --no-default-features keeps the binary size the same.
One more optimization is to strip symbols and debug info which takes some space considering our code size and it saves 20% more going down to 50M
comphead commentedon Feb 23, 2025
Stripped binary by inner segments
comphead commentedon Feb 23, 2025
so in the data above(ARM Macos) the biggest parts are
@alamb WDYT should we dig deeper?
comphead commentedon Feb 23, 2025
I checked the biggest methods are std panic methods, removing unwind can save even more
alamb commentedon Feb 24, 2025
I don't think so.
It is fascinating how much binary size we can save without unwinding.
logan-keede commentedon Mar 9, 2025
Optimizing binary size #13816
are we still considering this for GSoC Proposals as it is already closed, with binary size currently being 62M (on linux)?
[nix-shell:~/dev/datafusion]$ du -s -h target/release/datafusion-cli 62M target/release/datafusion-cliWe can probably still do the Ablative study, in which case maybe this should be reopened.
comphead commentedon Mar 10, 2025
Hey @logan-keede I would think this ticket is a good fit for GSoC #14510
logan-keede commentedon Mar 10, 2025
Thanks for the information, I would take a look at that.
alamb commentedon Mar 10, 2025
I personally think reducing the datafusion crate compile time somehow would be far more impactful than the binary size
datafusioncore crate) #13814IN other words it would make you a hero!
comphead commentedon Mar 10, 2025
Yeah, compile time would be closer to the original
Software Engineering, Refactoring, Dependency Management, Compilerstitlelogan-keede commentedon Mar 10, 2025
Thanks again, I believe this proposal might suit me even better considering my efforts over the last month or two.
You can look forward to a proposal draft soon! : )
alamb commentedon Mar 11, 2025
Thank you!
An ablative study would also be sweet!
logan-keede commentedon Mar 16, 2025
Hi @comphead, I would really appreciate if you can give me some feedback for my GSoC proposal.
Let me know if that is feasible or if there is anything else that I can do to make it easier for you.
PS: I dropped a draft of the same on your discord. However, it seems you are not active there.
comphead commentedon Mar 16, 2025
Hey @logan-keede please ping me in ASF slack, I'm not using discord now
logan-keede commentedon Mar 17, 2025
@comphead I pinged you on slack.