From 5cfb5df31e80dffa6afe4d2ba43e67d7f7730565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Wed, 10 Aug 2022 10:23:00 +0200 Subject: [PATCH 1/4] Set opt-level to 0 for debug builds But speed up compile times by optimising build dependencies of lindera --- Cargo.toml | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 90756bc1f..3a8eedc72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,19 +4,29 @@ members = ["milli", "filter-parser", "flatten-serde-json", "json-depth-checker", default-members = ["milli"] [profile.dev] -opt-level = 3 +opt-level = 0 [profile.release] debug = true codegen-units = 1 -# Make sure that the build scripts and proc-macros are compiled with -# all the optimizations. It speeds up the zip crate that we use in the build.rs. -[profile.dev.build-override] +[profile.dev.package.lindera-ipadic-builder] opt-level = 3 -[profile.release.build-override] +[profile.dev.package.encoding] opt-level = 3 -[profile.bench.build-override] +[profile.dev.package.yada] opt-level = 3 -[profile.test.build-override] + +[profile.release.package.lindera-ipadic-builder] +opt-level = 3 +[profile.release.package.encoding] +opt-level = 3 +[profile.release.package.yada] +opt-level = 3 + +[profile.bench.package.lindera-ipadic-builder] +opt-level = 3 +[profile.bench.package.encoding] +opt-level = 3 +[profile.bench.package.yada] opt-level = 3 From 98fc0938239754da99c7d2f9f1e3fec951afe04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Wed, 10 Aug 2022 13:54:06 +0200 Subject: [PATCH 2/4] Optimize a few performance sensitive dependencies on debug builds --- Cargo.toml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3a8eedc72..34e32a914 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,12 +4,17 @@ members = ["milli", "filter-parser", "flatten-serde-json", "json-depth-checker", default-members = ["milli"] [profile.dev] -opt-level = 0 +opt-level = 0 [profile.release] debug = true codegen-units = 1 +[profile.dev.package.grenad] +opt-level = 3 +[profile.dev.package.roaring] +opt-level = 3 + [profile.dev.package.lindera-ipadic-builder] opt-level = 3 [profile.dev.package.encoding] From 6fbf5dac68d68ee4f013b0a19dea33b75339195a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Wed, 10 Aug 2022 09:32:03 +0200 Subject: [PATCH 3/4] Simplify documents! macro to reduce compile times --- milli/src/documents/mod.rs | 44 +++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/milli/src/documents/mod.rs b/milli/src/documents/mod.rs index c1580309a..0bdf6600a 100644 --- a/milli/src/documents/mod.rs +++ b/milli/src/documents/mod.rs @@ -152,30 +152,33 @@ impl fmt::Display for Error { impl std::error::Error for Error {} +#[cfg(test)] +pub fn objects_from_json_value(json: serde_json::Value) -> Vec { + let documents = match json { + object @ serde_json::Value::Object(_) => vec![object], + serde_json::Value::Array(objects) => objects, + invalid => { + panic!("an array of objects must be specified, {:#?} is not an array", invalid) + } + }; + let mut objects = vec![]; + for document in documents { + let object = match document { + serde_json::Value::Object(object) => object, + invalid => panic!("an object must be specified, {:#?} is not an object", invalid), + }; + objects.push(object); + } + objects +} + /// Macro used to generate documents, with the same syntax as `serde_json::json` #[cfg(test)] macro_rules! documents { ($data:tt) => {{ let documents = serde_json::json!($data); - let documents = match documents { - object @ serde_json::Value::Object(_) => vec![object], - serde_json::Value::Array(objects) => objects, - invalid => { - panic!("an array of objects must be specified, {:#?} is not an array", invalid) - } - }; - - let mut builder = crate::documents::DocumentsBatchBuilder::new(Vec::new()); - for document in documents { - let object = match document { - serde_json::Value::Object(object) => object, - invalid => panic!("an object must be specified, {:#?} is not an object", invalid), - }; - builder.append_json_object(&object).unwrap(); - } - - let vector = builder.into_inner().unwrap(); - crate::documents::DocumentsBatchReader::from_reader(std::io::Cursor::new(vector)).unwrap() + let documents = $crate::documents::objects_from_json_value(documents); + $crate::documents::documents_batch_reader_from_objects(documents) }}; } @@ -187,7 +190,8 @@ pub fn documents_batch_reader_from_objects( for object in objects { builder.append_json_object(&object).unwrap(); } - DocumentsBatchReader::from_reader(std::io::Cursor::new(builder.into_inner().unwrap())).unwrap() + let vector = builder.into_inner().unwrap(); + DocumentsBatchReader::from_reader(std::io::Cursor::new(vector)).unwrap() } #[cfg(test)] From 53503f09ca3060a791a3509df8e3f8638aa861bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Tue, 16 Aug 2022 20:02:46 +0200 Subject: [PATCH 4/4] Make milli's default features optional in other executable targets --- benchmarks/Cargo.toml | 5 ++++- cli/Cargo.toml | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index 9c1e83663..87c567de9 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -7,7 +7,7 @@ publish = false [dependencies] anyhow = "1.0.56" csv = "1.1.6" -milli = { path = "../milli" } +milli = { path = "../milli", default-features = false } mimalloc = { version = "0.1.29", default-features = false } serde_json = { version = "1.0.79", features = ["preserve_order"] } @@ -24,6 +24,9 @@ convert_case = "0.5.0" flate2 = "1.0.22" reqwest = { version = "0.11.9", features = ["blocking", "rustls-tls"], default-features = false } +[features] +default = ["milli/default"] + [[bench]] name = "search_songs" harness = false diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 3e5df29c5..f1f5a6beb 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -12,9 +12,12 @@ color-eyre = "0.6.1" csv = "1.1.6" eyre = "0.6.7" indicatif = "0.16.2" -milli = { path = "../milli" } +milli = { path = "../milli", default-features = false } mimalloc = { version = "0.1.29", default-features = false } serde = "1.0.136" serde_json = "1.0.79" stderrlog = "0.5.1" structopt = "0.3.26" + +[features] +default = ["milli/default"]