Skip to content

Visual Studio Code, rebuilt in Rust

Rust

perf(editor): cut per-frame context work for the floating menu and output keys

rokartur98c417ada634
diff --git a/native/crates/app/src/output.rs b/native/crates/app/src/output.rs
index 3c29718f881..f2ae6418862 100644
--- a/native/crates/app/src/output.rs
+++ b/native/crates/app/src/output.rs
@@ -87,6 +87,8 @@ pub struct Output {
pub startup_log_levels: log_levels::DefaultLogLevels,
/// environmentService.argvResource.
pub argv_file: PathBuf,
+ /// argv.json's levels by its modification time: the output context keys ask on every frame.
+ argv_levels: std::cell::RefCell<Option<(Option<std::time::SystemTime>, log_levels::DefaultLogLevels)>>,
/// The loggers the workbench writes, created by `$createLogger`, and whether they log at every level.
written_loggers: Vec<(logger::LogFile, bool)>,
}
@@ -102,6 +104,7 @@ impl Default for Output {
log_level: DEFAULT_LOG_LEVEL,
startup_log_levels: log_levels::DefaultLogLevels::default(),
argv_file: PathBuf::new(),
+ argv_levels: std::cell::RefCell::default(),
written_loggers: Vec::new(),
}
}
@@ -229,7 +232,12 @@ impl Output {
/// defaultLogLevels.ts `defaultLogLevels`: argv.json's levels, the startup ones where it has none.
pub fn default_log_levels(&self) -> log_levels::DefaultLogLevels {
- let argv = log_levels::read_argv(&self.argv_file);
+ let modified = std::fs::metadata(&self.argv_file).and_then(|metadata| metadata.modified()).ok();
+ let mut cached = self.argv_levels.borrow_mut();
+ if cached.as_ref().is_none_or(|(at, _)| *at != modified) {
+ *cached = Some((modified, log_levels::read_argv(&self.argv_file)));
+ }
+ let argv = cached.as_ref().expect("filled above").1.clone();
if argv == log_levels::DefaultLogLevels::default() {
return self.startup_log_levels.clone();
}
diff --git a/native/crates/app/src/workbench/floating_menu.rs b/native/crates/app/src/workbench/floating_menu.rs
index 14a257398be..6bbf31a7505 100644
--- a/native/crates/app/src/workbench/floating_menu.rs
+++ b/native/crates/app/src/workbench/floating_menu.rs
@@ -69,6 +69,10 @@ impl Workbench {
if self.is_user_keybindings(editor) {
actions.push(FloatingAction { command: DEFINE_KEYBINDING_COMMAND.into(), title: "Define Keybinding".into(), enabled: true });
}
+ // The editor draws this every frame; most windows have no EditorContent item to evaluate a context for.
+ if !self.menus.iter().any(|item| item.menu == MenuId::EditorContent) {
+ return actions;
+ }
for action in menu_actions(&self.menus, MenuId::EditorContent, &self.key_context(window)) {
if let MenuAction::Command { id, title, enabled, .. } = action {
actions.push(FloatingAction { command: id, title, enabled });