nushell / reedline

A feature-rich line editor - powering Nushell
https://docs.rs/reedline/
MIT License
547 stars 152 forks source link

Make chrono optional #438

Open sigmaSd opened 2 years ago

sigmaSd commented 2 years ago

Chrono is a relatively big dependency, at least making it optional would allow user to choose to remove it

cargo bloat: chrono alone is adding 1.1% to text section

File  .text    Size    Crate Name
0.1%   1.2% 19.4KiB      std addr2line::ResDwarf<R>::parse
0.1%   1.1% 18.4KiB      std std::backtrace_rs::symbolize::gimli::resolve::{{closure}}
0.1%   0.7% 11.7KiB reedline reedline::engine::Reedline::handle_editor_event
0.1%   0.6% 10.7KiB reedline reedline::main
0.0%   0.6%  9.5KiB      std addr2line::ResUnit<R>::parse_lines
0.0%   0.6%  9.4KiB   chrono <chrono::format::strftime::StrftimeItems as core::iter::traits::iterator::Iterator>::next
0.0%   0.5%  8.5KiB      std miniz_oxide::inflate::core::decompress
0.0%   0.5%  7.6KiB   chrono chrono::format::format_inner

here is an example implementation https://github.com/nushell/reedline/compare/main...sigmaSd:opt_chrono?expand=1

comparison with this pr

# with chrono
cargo tree | wc -l
> 88
# without chrono
 cargo tree --no-default-features | wc -l
> 77
sholderbach commented 2 years ago

Do you happen to know an alternative light weight crate for that task? In this case it is just needed for the basic timestamp in the example Prompt and now in the History with metadata (#401)

phiresky commented 2 years ago

that can probably also be done with std::time::SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) (same for the use for database history in nushell itself)

sholderbach commented 2 years ago

For the time-stamping in the db that should be fine (if timezone or strict ordering concerns are not an issue). I don't recall the std library directly providing the formatting machinery for it to be useful in the example prompt (but yeah making a dependency for that a disable-able default feature could be an option for the dependency conscious)