Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(lsp): More granular locking of FileSystemDocuments #23291

Merged
merged 3 commits into from
Apr 9, 2024

Conversation

nathanwhit
Copy link
Member

Previously we locked the entire FileSystemDocuments even for lookups, causing contention. This was particularly bad because some of the hot ops (namely op_resolve) can end up hitting that lock under contention.

This PR replaces the mutex with synchronization internal to FileSystemDocuments (an AtomicBool for the dirty flag, and then a DashMap for the actual documents).

I need to think a bit more about whether or not this introduces any problematic race conditions.

@@ -1528,7 +1557,7 @@ impl Documents {
reqs
});
self.dirty = false;
file_system_docs.dirty = false;
self.file_system_docs.set_dirty(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If something else comes along while this is running and marks it as dirty, then this will change it as not dirty. Is that a concern? Maybe instead it should swap the value and mark it as not dirty above? Something like:

let is_fs_docs_dirty = self.file_system_docs.set_dirty(false); // make sure this is always done
if is_fs_docs_dirty && !self.dirty {

@bartlomieju
Copy link
Member

Just took a profile of this change, I no longer see op_script_names being blocked for hundreds of ms!

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nathanwhit nathanwhit merged commit f23155b into denoland:main Apr 9, 2024
17 checks passed
@nathanwhit nathanwhit deleted the fs-doc-lock branch April 9, 2024 22:12
satyarohith pushed a commit that referenced this pull request Apr 11, 2024
Previously we locked the entire `FileSystemDocuments` even for lookups,
causing contention. This was particularly bad because some of the hot
ops (namely `op_resolve`) can end up hitting that lock under contention.

This PR replaces the mutex with synchronization internal to
`FileSystemDocuments` (an `AtomicBool` for the dirty flag, and then a
`DashMap` for the actual documents).

I need to think a bit more about whether or not this introduces any
problematic race conditions.
littledivy pushed a commit to littledivy/deno that referenced this pull request Apr 19, 2024
…3291)

Previously we locked the entire `FileSystemDocuments` even for lookups,
causing contention. This was particularly bad because some of the hot
ops (namely `op_resolve`) can end up hitting that lock under contention.

This PR replaces the mutex with synchronization internal to
`FileSystemDocuments` (an `AtomicBool` for the dirty flag, and then a
`DashMap` for the actual documents).

I need to think a bit more about whether or not this introduces any
problematic race conditions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants