aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cli/src/analysis_bench.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_cli/src/analysis_bench.rs')
-rw-r--r--crates/ra_cli/src/analysis_bench.rs38
1 files changed, 31 insertions, 7 deletions
diff --git a/crates/ra_cli/src/analysis_bench.rs b/crates/ra_cli/src/analysis_bench.rs
index 5e9d0c16d..9e76bcebf 100644
--- a/crates/ra_cli/src/analysis_bench.rs
+++ b/crates/ra_cli/src/analysis_bench.rs
@@ -1,10 +1,14 @@
1use std::{ 1use std::{
2 path::{Path, PathBuf}, 2 path::{Path, PathBuf},
3 sync::Arc,
3 time::Instant, 4 time::Instant,
4}; 5};
5 6
6use ra_db::{salsa::Database, SourceDatabase}; 7use ra_db::{
7use ra_ide_api::{Analysis, AnalysisHost, FilePosition, LineCol}; 8 salsa::{Database, Durability},
9 FileId, SourceDatabase,
10};
11use ra_ide_api::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol};
8 12
9use crate::Result; 13use crate::Result;
10 14
@@ -16,7 +20,7 @@ pub(crate) enum Op {
16pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { 20pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
17 let start = Instant::now(); 21 let start = Instant::now();
18 eprint!("loading: "); 22 eprint!("loading: ");
19 let (host, roots) = ra_batch::load_cargo(path)?; 23 let (mut host, roots) = ra_batch::load_cargo(path)?;
20 let db = host.raw_database(); 24 let db = host.raw_database();
21 eprintln!("{:?}\n", start.elapsed()); 25 eprintln!("{:?}\n", start.elapsed());
22 26
@@ -44,7 +48,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
44 48
45 match op { 49 match op {
46 Op::Highlight { .. } => { 50 Op::Highlight { .. } => {
47 let res = do_work(&host, |analysis| { 51 let res = do_work(&mut host, file_id, |analysis| {
48 analysis.diagnostics(file_id).unwrap(); 52 analysis.diagnostics(file_id).unwrap();
49 analysis.highlight_as_html(file_id, false).unwrap() 53 analysis.highlight_as_html(file_id, false).unwrap()
50 }); 54 });
@@ -59,7 +63,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
59 .offset(LineCol { line, col_utf16: column }); 63 .offset(LineCol { line, col_utf16: column });
60 let file_postion = FilePosition { file_id, offset }; 64 let file_postion = FilePosition { file_id, offset };
61 65
62 let res = do_work(&host, |analysis| analysis.completions(file_postion)); 66 let res = do_work(&mut host, file_id, |analysis| analysis.completions(file_postion));
63 if verbose { 67 if verbose {
64 println!("\n{:#?}", res); 68 println!("\n{:#?}", res);
65 } 69 }
@@ -68,7 +72,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
68 Ok(()) 72 Ok(())
69} 73}
70 74
71fn do_work<F: Fn(&Analysis) -> T, T>(host: &AnalysisHost, work: F) -> T { 75fn do_work<F: Fn(&Analysis) -> T, T>(host: &mut AnalysisHost, file_id: FileId, work: F) -> T {
72 { 76 {
73 let start = Instant::now(); 77 let start = Instant::now();
74 eprint!("from scratch: "); 78 eprint!("from scratch: ");
@@ -84,7 +88,27 @@ fn do_work<F: Fn(&Analysis) -> T, T>(host: &AnalysisHost, work: F) -> T {
84 { 88 {
85 let start = Instant::now(); 89 let start = Instant::now();
86 eprint!("trivial change: "); 90 eprint!("trivial change: ");
87 host.raw_database().salsa_runtime().next_revision(); 91 host.raw_database().salsa_runtime().synthetic_write(Durability::LOW);
92 work(&host.analysis());
93 eprintln!("{:?}", start.elapsed());
94 }
95 {
96 let start = Instant::now();
97 eprint!("comment change: ");
98 {
99 let mut text = host.analysis().file_text(file_id).unwrap().to_string();
100 text.push_str("\n/* Hello world */\n");
101 let mut change = AnalysisChange::new();
102 change.change_file(file_id, Arc::new(text));
103 host.apply_change(change);
104 }
105 work(&host.analysis());
106 eprintln!("{:?}", start.elapsed());
107 }
108 {
109 let start = Instant::now();
110 eprint!("const change: ");
111 host.raw_database().salsa_runtime().synthetic_write(Durability::HIGH);
88 let res = work(&host.analysis()); 112 let res = work(&host.analysis());
89 eprintln!("{:?}", start.elapsed()); 113 eprintln!("{:?}", start.elapsed());
90 res 114 res