Skip to content

Commit

Permalink
[move-analyzer] Cache user program (#20621)
Browse files Browse the repository at this point in the history
## Description 

This PR builds upon the compiler changes supporting partial compilation
of of user code (skipping function bodies when compiling specific files
designated by the user) to deliver the performance improvements
described in the [PR](#20588)
containing the compiler changes (reducing compilation time in the IDE
for the Deepbook package from over 1s to less than 200ms).

In this PR, in addition to caching dependencies, we also cache user
code, fully compile only modified files, and merge result of this
compilation with the cached data


## Test plan 

All tests must pass. Also tested manually to verify correctness and
performance improvements
  • Loading branch information
awelc authored Dec 18, 2024
1 parent f18b17d commit ac03618
Show file tree
Hide file tree
Showing 4 changed files with 335 additions and 175 deletions.
10 changes: 5 additions & 5 deletions external-crates/move/crates/move-analyzer/src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ pub fn run() {

let (connection, io_threads) = Connection::stdio();
let symbols_map = Arc::new(Mutex::new(BTreeMap::new()));
let pkg_deps = Arc::new(Mutex::new(BTreeMap::<
PathBuf,
symbols::PrecomputedPkgDepsInfo,
>::new()));
let pkg_deps = Arc::new(Mutex::new(
BTreeMap::<PathBuf, symbols::PrecomputedPkgInfo>::new(),
));
let ide_files_root: VfsPath = MemoryFS::new().into();

let (id, client_response) = connection
Expand Down Expand Up @@ -154,6 +153,7 @@ pub fn run() {
Arc::new(Mutex::new(BTreeMap::new())),
ide_files_root.clone(),
p.as_path(),
None,
lint,
None,
) {
Expand Down Expand Up @@ -279,7 +279,7 @@ fn on_request(
context: &Context,
request: &Request,
ide_files_root: VfsPath,
pkg_dependencies: Arc<Mutex<BTreeMap<PathBuf, symbols::PrecomputedPkgDepsInfo>>>,
pkg_dependencies: Arc<Mutex<BTreeMap<PathBuf, symbols::PrecomputedPkgInfo>>>,
shutdown_request_received: bool,
) -> bool {
if shutdown_request_received {
Expand Down
11 changes: 6 additions & 5 deletions external-crates/move/crates/move-analyzer/src/completions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
utils::{completion_item, PRIMITIVE_TYPE_COMPLETIONS},
},
context::Context,
symbols::{self, CursorContext, PrecomputedPkgDepsInfo, SymbolicatorRunner, Symbols},
symbols::{self, CursorContext, PrecomputedPkgInfo, SymbolicatorRunner, Symbols},
};
use lsp_server::Request;
use lsp_types::{CompletionItem, CompletionItemKind, CompletionParams, Position};
Expand Down Expand Up @@ -78,7 +78,7 @@ pub fn on_completion_request(
context: &Context,
request: &Request,
ide_files_root: VfsPath,
pkg_dependencies: Arc<Mutex<BTreeMap<PathBuf, PrecomputedPkgDepsInfo>>>,
pkg_dependencies: Arc<Mutex<BTreeMap<PathBuf, PrecomputedPkgInfo>>>,
) {
eprintln!("handling completion request");
let parameters = serde_json::from_value::<CompletionParams>(request.params.clone())
Expand Down Expand Up @@ -119,7 +119,7 @@ pub fn on_completion_request(
fn completions(
context: &Context,
ide_files_root: VfsPath,
pkg_dependencies: Arc<Mutex<BTreeMap<PathBuf, PrecomputedPkgDepsInfo>>>,
pkg_dependencies: Arc<Mutex<BTreeMap<PathBuf, PrecomputedPkgInfo>>>,
path: &Path,
pos: Position,
) -> Option<Vec<CompletionItem>> {
Expand All @@ -143,7 +143,7 @@ fn completions(
pub fn compute_completions(
current_symbols: &Symbols,
ide_files_root: VfsPath,
pkg_dependencies: Arc<Mutex<BTreeMap<PathBuf, PrecomputedPkgDepsInfo>>>,
pkg_dependencies: Arc<Mutex<BTreeMap<PathBuf, PrecomputedPkgInfo>>>,
path: &Path,
pos: Position,
) -> Vec<CompletionItem> {
Expand All @@ -156,7 +156,7 @@ pub fn compute_completions(
/// view of the code (returns `None` if the symbols could not be re-computed).
fn compute_completions_new_symbols(
ide_files_root: VfsPath,
pkg_dependencies: Arc<Mutex<BTreeMap<PathBuf, PrecomputedPkgDepsInfo>>>,
pkg_dependencies: Arc<Mutex<BTreeMap<PathBuf, PrecomputedPkgInfo>>>,
path: &Path,
cursor_position: Position,
) -> Option<Vec<CompletionItem>> {
Expand All @@ -170,6 +170,7 @@ fn compute_completions_new_symbols(
pkg_dependencies,
ide_files_root,
&pkg_path,
Some(vec![path.to_path_buf()]),
LintLevel::None,
cursor_info,
)
Expand Down
Loading

0 comments on commit ac03618

Please sign in to comment.