diff --git a/Cargo.lock b/Cargo.lock index 7a742d3..c06ebae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1271,6 +1271,7 @@ dependencies = [ "ipnetwork", "log", "memchr", + "memmap2", "serde", "thiserror 2.0.12", ] @@ -1281,6 +1282,15 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memmap2" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f" +dependencies = [ + "libc", +] + [[package]] name = "mime" version = "0.3.17" diff --git a/Cargo.toml b/Cargo.toml index 1036213..e1ed057 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ env_logger = "=0.11.8" fancy-regex = "=0.14.0" futures = "=0.3.31" log = "=0.4.27" -maxminddb = "=0.26.0" +maxminddb = { version = "=0.26.0", features = ["mmap"] } ratatui = { version = "=0.29.0", optional = true } rlimit = "=0.10.2" serde = "=1.0.219" diff --git a/src/output.rs b/src/output.rs index 7495c0d..b509837 100644 --- a/src/output.rs +++ b/src/output.rs @@ -47,10 +47,12 @@ pub async fn save_proxies( let maybe_mmdb = if config.enable_geolocation { let geodb_path = get_geodb_path().await.wrap_err("failed to get GeoDB path")?; - let buffer = tokio::fs::read(&geodb_path).await.wrap_err_with( - move || format!("failed to read {}", geodb_path.display()), - )?; - Some(maxminddb::Reader::from_source(buffer)?) + Some( + tokio::task::spawn_blocking(move || { + maxminddb::Reader::open_mmap(geodb_path) + }) + .await??, + ) } else { None };