perf: do not depend on iana-time-zone (#18088)

Chrono's `clock` feature pulls in `iana-time-zone` which links to macOS
core_foundation. This PR itself is not enough to get rid of
CoreFoundation. Removal depends on getting rid of security framework,
see #18071
This commit is contained in:
Divy Srivastava 2023-03-15 12:44:22 +05:30 committed by GitHub
parent 6f9c0a9b7a
commit 51649272bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 90 deletions

85
Cargo.lock generated
View file

@ -442,10 +442,8 @@ version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1"
dependencies = [
"iana-time-zone",
"num-integer",
"num-traits",
"winapi",
]
[[package]]
@ -699,50 +697,6 @@ dependencies = [
"zeroize",
]
[[package]]
name = "cxx"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc831ee6a32dd495436e317595e639a587aa9907bef96fe6e6abc290ab6204e9"
dependencies = [
"cc",
"cxxbridge-flags",
"cxxbridge-macro",
"link-cplusplus",
]
[[package]]
name = "cxx-build"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94331d54f1b1a8895cd81049f7eaaaef9d05a7dcb4d1fd08bf3ff0806246789d"
dependencies = [
"cc",
"codespan-reporting",
"once_cell",
"proc-macro2 1.0.51",
"quote 1.0.23",
"scratch",
"syn 1.0.107",
]
[[package]]
name = "cxxbridge-flags"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48dcd35ba14ca9b40d6e4b4b39961f23d835dbb8eed74565ded361d93e1feb8a"
[[package]]
name = "cxxbridge-macro"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81bbeb29798b407ccd82a3324ade1a7286e0d29851475990b612670f6f5124d2"
dependencies = [
"proc-macro2 1.0.51",
"quote 1.0.23",
"syn 1.0.107",
]
[[package]]
name = "d3d12"
version = "0.6.0"
@ -2382,30 +2336,6 @@ dependencies = [
"tokio-rustls",
]
[[package]]
name = "iana-time-zone"
version = "0.1.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"winapi",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca"
dependencies = [
"cxx",
"cxx-build",
]
[[package]]
name = "ident_case"
version = "1.0.1"
@ -2784,15 +2714,6 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "link-cplusplus"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
dependencies = [
"cc",
]
[[package]]
name = "linked-hash-map"
version = "0.5.6"
@ -4034,12 +3955,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "scratch"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
[[package]]
name = "sct"
version = "0.7.0"

View file

@ -58,7 +58,7 @@ atty.workspace = true
base32 = "=0.4.0"
base64.workspace = true
cache_control.workspace = true
chrono = { version = "=0.4.22", default-features = false, features = ["clock"] }
chrono = { version = "=0.4.22", default-features = false, features = ["std"] }
clap = "=3.1.12"
clap_complete = "=3.1.2"
clap_complete_fig = "=3.1.5"

View file

@ -13,6 +13,8 @@ use std::process::Command;
use std::process::Stdio;
use std::time::SystemTime;
include!("../util/time.rs");
mod http;
mod lsp;
@ -436,8 +438,7 @@ async fn main() -> Result<()> {
env::set_current_dir(test_util::root_path())?;
let mut new_data = BenchResult {
created_at: chrono::Utc::now()
.to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
created_at: utc_now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
sha1: test_util::run_collect(
&["git", "rev-parse", "HEAD"],
None,

View file

@ -9,6 +9,7 @@ use crate::http_util::HttpClient;
use crate::proc_state::ProcState;
use crate::util::progress_bar::ProgressBar;
use crate::util::progress_bar::ProgressBarStyle;
use crate::util::time;
use crate::version;
use deno_core::anyhow::bail;
@ -60,7 +61,7 @@ impl RealUpdateCheckerEnvironment {
http_client,
cache_file_path,
// cache the current time
current_time: chrono::Utc::now(),
current_time: time::utc_now(),
}
}
}
@ -702,7 +703,7 @@ mod test {
file_text: Default::default(),
current_version: Default::default(),
latest_version: Arc::new(Mutex::new(Ok("".to_string()))),
time: Arc::new(Mutex::new(chrono::Utc::now())),
time: Arc::new(Mutex::new(crate::util::time::utc_now())),
}
}

View file

@ -12,6 +12,7 @@ pub mod logger;
pub mod path;
pub mod progress_bar;
pub mod text_encoding;
pub mod time;
pub mod unix;
pub mod v8;
pub mod windows;

22
cli/util/time.rs Normal file
View file

@ -0,0 +1,22 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
/// Identical to chrono::Utc::now() but without the system "clock"
/// feature flag.
///
/// The "clock" feature flag pulls in the "iana-time-zone" crate
/// which links to macOS's "CoreFoundation" framework which increases
/// startup time for the CLI.
///
/// You can simply include this file in your project using
/// `include!("path/to/cli/util/time.rs"))` and use it
/// as a drop-in replacement for chrono::Utc::now().
pub fn utc_now() -> chrono::DateTime<chrono::Utc> {
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("system time before Unix epoch");
let naive = chrono::NaiveDateTime::from_timestamp(
now.as_secs() as i64,
now.subsec_nanos(),
);
chrono::DateTime::from_utc(naive, chrono::Utc)
}