5222: Add Item change to the set of benches r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-07-04 15:04:57 +00:00 committed by GitHub
commit 08108d29b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 15 deletions

View File

@ -3,13 +3,14 @@
//! If run started args, we run the LSP server loop. With a subcommand, we do a //! If run started args, we run the LSP server loop. With a subcommand, we do a
//! one-time batch processing. //! one-time batch processing.
use std::{env, fmt::Write, path::PathBuf};
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use pico_args::Arguments; use pico_args::Arguments;
use ra_db::AbsPathBuf;
use ra_ssr::{SsrPattern, SsrRule}; use ra_ssr::{SsrPattern, SsrRule};
use rust_analyzer::cli::{BenchWhat, Position, Verbosity}; use rust_analyzer::cli::{BenchWhat, Position, Verbosity};
use std::{fmt::Write, path::PathBuf};
pub(crate) struct Args { pub(crate) struct Args {
pub(crate) verbosity: Verbosity, pub(crate) verbosity: Verbosity,
pub(crate) command: Command, pub(crate) command: Command,
@ -240,7 +241,10 @@ ARGS:
let complete_path: Option<Position> = matches.opt_value_from_str("--complete")?; let complete_path: Option<Position> = matches.opt_value_from_str("--complete")?;
let goto_def_path: Option<Position> = matches.opt_value_from_str("--goto-def")?; let goto_def_path: Option<Position> = matches.opt_value_from_str("--goto-def")?;
let what = match (highlight_path, complete_path, goto_def_path) { let what = match (highlight_path, complete_path, goto_def_path) {
(Some(path), None, None) => BenchWhat::Highlight { path: path.into() }, (Some(path), None, None) => {
let path = env::current_dir().unwrap().join(path);
BenchWhat::Highlight { path: AbsPathBuf::assert(path) }
}
(None, Some(position), None) => BenchWhat::Complete(position), (None, Some(position), None) => BenchWhat::Complete(position),
(None, None, Some(position)) => BenchWhat::GotoDef(position), (None, None, Some(position)) => BenchWhat::GotoDef(position),
_ => panic!( _ => panic!(

View File

@ -1,12 +1,6 @@
//! Benchmark operations like highlighting or goto definition. //! Benchmark operations like highlighting or goto definition.
use std::{ use std::{env, path::Path, str::FromStr, sync::Arc, time::Instant};
convert::TryFrom,
path::{Path, PathBuf},
str::FromStr,
sync::Arc,
time::Instant,
};
use anyhow::{format_err, Result}; use anyhow::{format_err, Result};
use ra_db::{ use ra_db::{
@ -18,13 +12,13 @@ use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CompletionConfig, FilePosit
use crate::cli::{load_cargo::load_cargo, Verbosity}; use crate::cli::{load_cargo::load_cargo, Verbosity};
pub enum BenchWhat { pub enum BenchWhat {
Highlight { path: PathBuf }, Highlight { path: AbsPathBuf },
Complete(Position), Complete(Position),
GotoDef(Position), GotoDef(Position),
} }
pub struct Position { pub struct Position {
pub path: PathBuf, pub path: AbsPathBuf,
pub line: u32, pub line: u32,
pub column: u32, pub column: u32,
} }
@ -34,7 +28,9 @@ impl FromStr for Position {
fn from_str(s: &str) -> Result<Self> { fn from_str(s: &str) -> Result<Self> {
let (path_line, column) = rsplit_at_char(s, ':')?; let (path_line, column) = rsplit_at_char(s, ':')?;
let (path, line) = rsplit_at_char(path_line, ':')?; let (path, line) = rsplit_at_char(path_line, ':')?;
Ok(Position { path: path.into(), line: line.parse()?, column: column.parse()? }) let path = env::current_dir().unwrap().join(path);
let path = AbsPathBuf::assert(path);
Ok(Position { path, line: line.parse()?, column: column.parse()? })
} }
} }
@ -62,8 +58,7 @@ pub fn analysis_bench(
BenchWhat::Highlight { path } => path, BenchWhat::Highlight { path } => path,
BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => &pos.path, BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => &pos.path,
}; };
let path = AbsPathBuf::try_from(path.clone()).unwrap(); let path = path.clone().into();
let path = path.into();
vfs.file_id(&path).ok_or_else(|| format_err!("Can't find {}", path))? vfs.file_id(&path).ok_or_else(|| format_err!("Can't find {}", path))?
}; };
@ -139,6 +134,19 @@ fn do_work<F: Fn(&Analysis) -> T, T>(host: &mut AnalysisHost, file_id: FileId, w
work(&host.analysis()); work(&host.analysis());
eprintln!("{:?}", start.elapsed()); eprintln!("{:?}", start.elapsed());
} }
{
let start = Instant::now();
eprint!("item change: ");
{
let mut text = host.analysis().file_text(file_id).unwrap().to_string();
text.push_str("\npub fn _dummy() {}\n");
let mut change = AnalysisChange::new();
change.change_file(file_id, Some(Arc::new(text)));
host.apply_change(change);
}
work(&host.analysis());
eprintln!("{:?}", start.elapsed());
}
{ {
let start = Instant::now(); let start = Instant::now();
eprint!("const change: "); eprint!("const change: ");