Auto merge of #14410 - Veykril:query-lru-capacities, r=Veykril

internal: Add config to specifiy lru capacities for all queries

Might help figuring out what queries should be limited by LRU by default, as currently we only limit `parse`, `parse_macro_expansion` and `macro_expand`.
This commit is contained in:
bors 2023-03-30 12:20:24 +00:00
commit fc8c5139fa
8 changed files with 202 additions and 9 deletions

View file

@ -7,7 +7,7 @@
//! configure the server itself, feature flags are passed into analysis, and
//! tweak things like automatic insertion of `()` in completions.
use std::{fmt, iter, path::PathBuf};
use std::{fmt, iter, ops::Not, path::PathBuf};
use flycheck::FlycheckConfig;
use ide::{
@ -418,6 +418,8 @@ config_data! {
/// Number of syntax trees rust-analyzer keeps in memory. Defaults to 128.
lru_capacity: Option<usize> = "null",
/// Sets the LRU capacity of the specified queries.
lru_query_capacities: FxHashMap<Box<str>, usize> = "{}",
/// Whether to show `can't find Cargo.toml` error message.
notifications_cargoTomlNotFound: bool = "true",
@ -1085,10 +1087,14 @@ impl Config {
extra_env
}
pub fn lru_capacity(&self) -> Option<usize> {
pub fn lru_parse_query_capacity(&self) -> Option<usize> {
self.data.lru_capacity
}
pub fn lru_query_capacities(&self) -> Option<&FxHashMap<Box<str>, usize>> {
self.data.lru_query_capacities.is_empty().not().then(|| &self.data.lru_query_capacities)
}
pub fn proc_macro_srv(&self) -> Option<(AbsPathBuf, /* is path explicitly set */ bool)> {
if !self.data.procMacro_enable {
return None;
@ -2024,6 +2030,9 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
"FxHashMap<String, String>" => set! {
"type": "object",
},
"FxHashMap<Box<str>, usize>" => set! {
"type": "object",
},
"Option<usize>" => set! {
"type": ["null", "integer"],
"minimum": 0,

View file

@ -141,7 +141,10 @@ impl GlobalState {
Handle { handle, receiver }
};
let analysis_host = AnalysisHost::new(config.lru_capacity());
let mut analysis_host = AnalysisHost::new(config.lru_parse_query_capacity());
if let Some(capacities) = config.lru_query_capacities() {
analysis_host.update_lru_capacities(capacities);
}
let (flycheck_sender, flycheck_receiver) = unbounded();
let mut this = GlobalState {
sender,

View file

@ -74,8 +74,13 @@ impl GlobalState {
pub(crate) fn update_configuration(&mut self, config: Config) {
let _p = profile::span("GlobalState::update_configuration");
let old_config = mem::replace(&mut self.config, Arc::new(config));
if self.config.lru_capacity() != old_config.lru_capacity() {
self.analysis_host.update_lru_capacity(self.config.lru_capacity());
if self.config.lru_parse_query_capacity() != old_config.lru_parse_query_capacity() {
self.analysis_host.update_lru_capacity(self.config.lru_parse_query_capacity());
}
if self.config.lru_query_capacities() != old_config.lru_query_capacities() {
self.analysis_host.update_lru_capacities(
&self.config.lru_query_capacities().cloned().unwrap_or_default(),
);
}
if self.config.linked_projects() != old_config.linked_projects() {
self.fetch_workspaces_queue.request_op("linked projects changed".to_string(), ())