From 8acd3f50bb224d2804616db975fd5b55f66ed5da Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Wed, 31 Jul 2024 09:53:00 +0200 Subject: [PATCH] skip normalization when the locales and values are the same --- .../extract/extract_facet_string_docids.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/milli/src/update/index_documents/extract/extract_facet_string_docids.rs b/milli/src/update/index_documents/extract/extract_facet_string_docids.rs index 6452a67a1..f1ac07deb 100644 --- a/milli/src/update/index_documents/extract/extract_facet_string_docids.rs +++ b/milli/src/update/index_documents/extract/extract_facet_string_docids.rs @@ -68,10 +68,18 @@ pub fn extract_facet_string_docids( // Facet search normalization { - let locales = settings_diff.old.localized_faceted_fields_ids.locales(field_id); - let old_hyper_normalized_value = normalize_facet_string(normalized_value, locales); - let locales = settings_diff.new.localized_faceted_fields_ids.locales(field_id); - let new_hyper_normalized_value = normalize_facet_string(normalized_value, locales); + let old_locales = settings_diff.old.localized_faceted_fields_ids.locales(field_id); + let new_locales = settings_diff.new.localized_faceted_fields_ids.locales(field_id); + + if is_same_value && old_locales == new_locales { + // optimization: skip costly normalizations if the values and locales stayed the same + // TODO: splitting the cases between a settings diff and a document update would possibly allow for more optimizations, + // such as skipping the locales check when doing a documents update. + continue; + } + + let old_hyper_normalized_value = normalize_facet_string(normalized_value, old_locales); + let new_hyper_normalized_value = normalize_facet_string(normalized_value, new_locales); let set = BTreeSet::from_iter(std::iter::once(normalized_value));