Skip to content

Version 0.3.1995 rust-analyzer process spins out of control in macOS VSCode #17409

Closed
@davidhewitt

Description

@davidhewitt

Followup of #17378 - as similar to #17378 (comment) I am also still experiencing the same issue of high CPU on version 0.3.1995 (and also on main at fa486e6).

Doing some debugging locally, I find that the infinite loop mentioned in #17378 (comment) seems to still the culprit.

I inserted a debug print:

$ git diff 
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index e8504979b..546f1e49a 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -2532,6 +2532,7 @@ macro_rules! _impl_for_config_data {
                 $vis fn $field(&self, source_root: Option<SourceRootId>) -> &$ty {
                     let mut par: Option<SourceRootId> = source_root;
                     while let Some(source_root_id) = par {
+                        dbg!(source_root_id, &self.source_root_parent_map);
                         par = self.source_root_parent_map.get(&source_root_id).copied();
                         if let Some((config, _)) = self.ratoml_files.get(&source_root_id) {
                             if let Some(value) = config.$field.as_ref() {

... and this is my output:

[crates/rust-analyzer/src/config.rs:336:1] source_root_id = SourceRootId(
    200,
)
[crates/rust-analyzer/src/config.rs:336:1] &self.source_root_parent_map = {
    SourceRootId(
        202,
    ): SourceRootId(
        200,
    ),
    SourceRootId(
        200,
    ): SourceRootId(
        202,
    ),
    // elided for brevity
}
[crates/rust-analyzer/src/config.rs:336:1] source_root_id = SourceRootId(
    202,
)
[crates/rust-analyzer/src/config.rs:336:1] &self.source_root_parent_map = {
    SourceRootId(
        202,
    ): SourceRootId(
        200,
    ),
    SourceRootId(
        200,
    ): SourceRootId(
        202,
    ),
    // elided for brevity
}
// and repeat ad infinitum between source root 202 and 200

So I think the patch in #17381 is probably insufficient because here I don't have a source root with a parent of itself; instead somehow I have a cycle between two source roots 202 and 200.

I guess there's brute force solutions to prevent this infinite loop like bailing out if the number of iterations ever exceeds the total size of source_root_parent_map. Or maybe there's similar ideas to #17381 that can prune this graph.

... I would go further and submit a patch but I really need to go to sleep, sorry 🙈

cc @Veykril @roife

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions