language: Optimize language_for_file (#28671)

While working on #28670 this function showed up in my profiles; this PR
makes it evaluate some of it's conditions lazily + prevent constant
rebuilding of globset::Candidates.

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Piotr Osiewicz 2025-04-14 13:18:45 +02:00 committed by GitHub
parent 5e57f148ac
commit 98891e4c70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 28 deletions

View file

@ -2,7 +2,7 @@
use crate::{File, Language, LanguageName, LanguageServerName};
use anyhow::Result;
use collections::{HashMap, HashSet};
use collections::{FxHashMap, HashMap, HashSet};
use core::slice;
use ec4rs::{
Properties as EditorconfigProperties,
@ -63,7 +63,7 @@ pub struct AllLanguageSettings {
pub edit_predictions: EditPredictionSettings,
pub defaults: LanguageSettings,
languages: HashMap<LanguageName, LanguageSettings>,
pub(crate) file_types: HashMap<Arc<str>, GlobSet>,
pub(crate) file_types: FxHashMap<Arc<str>, GlobSet>,
}
/// The settings for a particular language.
@ -1217,7 +1217,7 @@ impl settings::Settings for AllLanguageSettings {
.map(|settings| settings.enabled_in_assistant)
.unwrap_or(true);
let mut file_types: HashMap<Arc<str>, GlobSet> = HashMap::default();
let mut file_types: FxHashMap<Arc<str>, GlobSet> = FxHashMap::default();
for (language, suffixes) in &default_value.file_types {
let mut builder = GlobSetBuilder::new();