aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-04 16:04:57 +0100
committerGitHub <[email protected]>2020-07-04 16:04:57 +0100
commit08108d29b271344886942741d84e49d8bb1ae5ae (patch)
treeafb5f2a3b459a463a84b117415b93789bbcf8594
parent1d3a3c078209c74daef2f4ee8450185c69022578 (diff)
parent3902e5574c56a4f0c7e0846afe61022ef4b4fc76 (diff)
Merge #5222
5222: Add Item change to the set of benches r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/rust-analyzer/src/bin/args.rs10
-rw-r--r--crates/rust-analyzer/src/cli/analysis_bench.rs32
2 files changed, 27 insertions, 15 deletions
diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs
index 8c0f4df8b..85c2e415a 100644
--- a/crates/rust-analyzer/src/bin/args.rs
+++ b/crates/rust-analyzer/src/bin/args.rs
@@ -3,13 +3,14 @@
3//! If run started args, we run the LSP server loop. With a subcommand, we do a 3//! If run started args, we run the LSP server loop. With a subcommand, we do a
4//! one-time batch processing. 4//! one-time batch processing.
5 5
6use std::{env, fmt::Write, path::PathBuf};
7
6use anyhow::{bail, Result}; 8use anyhow::{bail, Result};
7use pico_args::Arguments; 9use pico_args::Arguments;
10use ra_db::AbsPathBuf;
8use ra_ssr::{SsrPattern, SsrRule}; 11use ra_ssr::{SsrPattern, SsrRule};
9use rust_analyzer::cli::{BenchWhat, Position, Verbosity}; 12use rust_analyzer::cli::{BenchWhat, Position, Verbosity};
10 13
11use std::{fmt::Write, path::PathBuf};
12
13pub(crate) struct Args { 14pub(crate) struct Args {
14 pub(crate) verbosity: Verbosity, 15 pub(crate) verbosity: Verbosity,
15 pub(crate) command: Command, 16 pub(crate) command: Command,
@@ -240,7 +241,10 @@ ARGS:
240 let complete_path: Option<Position> = matches.opt_value_from_str("--complete")?; 241 let complete_path: Option<Position> = matches.opt_value_from_str("--complete")?;
241 let goto_def_path: Option<Position> = matches.opt_value_from_str("--goto-def")?; 242 let goto_def_path: Option<Position> = matches.opt_value_from_str("--goto-def")?;
242 let what = match (highlight_path, complete_path, goto_def_path) { 243 let what = match (highlight_path, complete_path, goto_def_path) {
243 (Some(path), None, None) => BenchWhat::Highlight { path: path.into() }, 244 (Some(path), None, None) => {
245 let path = env::current_dir().unwrap().join(path);
246 BenchWhat::Highlight { path: AbsPathBuf::assert(path) }
247 }
244 (None, Some(position), None) => BenchWhat::Complete(position), 248 (None, Some(position), None) => BenchWhat::Complete(position),
245 (None, None, Some(position)) => BenchWhat::GotoDef(position), 249 (None, None, Some(position)) => BenchWhat::GotoDef(position),
246 _ => panic!( 250 _ => panic!(
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs
index 930375d3e..90990d3e7 100644
--- a/crates/rust-analyzer/src/cli/analysis_bench.rs
+++ b/crates/rust-analyzer/src/cli/analysis_bench.rs
@@ -1,12 +1,6 @@
1//! Benchmark operations like highlighting or goto definition. 1//! Benchmark operations like highlighting or goto definition.
2 2
3use std::{ 3use std::{env, path::Path, str::FromStr, sync::Arc, time::Instant};
4 convert::TryFrom,
5 path::{Path, PathBuf},
6 str::FromStr,
7 sync::Arc,
8 time::Instant,
9};
10 4
11use anyhow::{format_err, Result}; 5use anyhow::{format_err, Result};
12use ra_db::{ 6use ra_db::{
@@ -18,13 +12,13 @@ use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CompletionConfig, FilePosit
18use crate::cli::{load_cargo::load_cargo, Verbosity}; 12use crate::cli::{load_cargo::load_cargo, Verbosity};
19 13
20pub enum BenchWhat { 14pub enum BenchWhat {
21 Highlight { path: PathBuf }, 15 Highlight { path: AbsPathBuf },
22 Complete(Position), 16 Complete(Position),
23 GotoDef(Position), 17 GotoDef(Position),
24} 18}
25 19
26pub struct Position { 20pub struct Position {
27 pub path: PathBuf, 21 pub path: AbsPathBuf,
28 pub line: u32, 22 pub line: u32,
29 pub column: u32, 23 pub column: u32,
30} 24}
@@ -34,7 +28,9 @@ impl FromStr for Position {
34 fn from_str(s: &str) -> Result<Self> { 28 fn from_str(s: &str) -> Result<Self> {
35 let (path_line, column) = rsplit_at_char(s, ':')?; 29 let (path_line, column) = rsplit_at_char(s, ':')?;
36 let (path, line) = rsplit_at_char(path_line, ':')?; 30 let (path, line) = rsplit_at_char(path_line, ':')?;
37 Ok(Position { path: path.into(), line: line.parse()?, column: column.parse()? }) 31 let path = env::current_dir().unwrap().join(path);
32 let path = AbsPathBuf::assert(path);
33 Ok(Position { path, line: line.parse()?, column: column.parse()? })
38 } 34 }
39} 35}
40 36
@@ -62,8 +58,7 @@ pub fn analysis_bench(
62 BenchWhat::Highlight { path } => path, 58 BenchWhat::Highlight { path } => path,
63 BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => &pos.path, 59 BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => &pos.path,
64 }; 60 };
65 let path = AbsPathBuf::try_from(path.clone()).unwrap(); 61 let path = path.clone().into();
66 let path = path.into();
67 vfs.file_id(&path).ok_or_else(|| format_err!("Can't find {}", path))? 62 vfs.file_id(&path).ok_or_else(|| format_err!("Can't find {}", path))?
68 }; 63 };
69 64
@@ -141,6 +136,19 @@ fn do_work<F: Fn(&Analysis) -> T, T>(host: &mut AnalysisHost, file_id: FileId, w
141 } 136 }
142 { 137 {
143 let start = Instant::now(); 138 let start = Instant::now();
139 eprint!("item change: ");
140 {
141 let mut text = host.analysis().file_text(file_id).unwrap().to_string();
142 text.push_str("\npub fn _dummy() {}\n");
143 let mut change = AnalysisChange::new();
144 change.change_file(file_id, Some(Arc::new(text)));
145 host.apply_change(change);
146 }
147 work(&host.analysis());
148 eprintln!("{:?}", start.elapsed());
149 }
150 {
151 let start = Instant::now();
144 eprint!("const change: "); 152 eprint!("const change: ");
145 host.raw_database_mut().salsa_runtime_mut().synthetic_write(Durability::HIGH); 153 host.raw_database_mut().salsa_runtime_mut().synthetic_write(Durability::HIGH);
146 let res = work(&host.analysis()); 154 let res = work(&host.analysis());