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

Trait solver taking >10s to finish in auto complete #19291

Open
g1684774 opened this issue Mar 5, 2025 · 1 comment
Open

Trait solver taking >10s to finish in auto complete #19291

g1684774 opened this issue Mar 5, 2025 · 1 comment
Labels
A-completion autocompletion A-perf performance issues C-bug Category: bug

Comments

@g1684774
Copy link

g1684774 commented Mar 5, 2025

rust-analyzer version: 2025-02-10

rustc version: nightly-2024-09-30 (1.83 nightly)

editor or extension: Neovim

repository link (if public, optional): https://github.com/a16z/jolt

While trying to auto-complete in this line, I get a really slow auto complete in the first run (17s) but it looks like the it's also not being cached because following completions are still slow.

The problem seems to be mostly related to Trait solver chalk since the project heavily uses ArkWorks and it's types are all defined around traits. I know there are plans to replace Chalk but in the meantime is there any suggestion on how to speed up completion in the project?

[ERROR][2025-03-05 14:02:10] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'   17437ms handle_completion\n      1604ms CompletionContext::new\n        1568ms CompletionContext::analyze\n          1568ms SemanticsImpl::analyze_impl\n            1568ms infer_query\n     15616ms import_on_the_fly_method @ potential_import_name = "" \n'
[ERROR][2025-03-05 14:02:10] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'       15613ms ImportAssets::search_for_imports\n         15613ms ImportAssets::search_for\n           15613ms ImportAssets::trait_applicable_items\n             15299ms iterate_method_candidates_with_traits\n               15299ms iterate_method_candidates_dyn @ with_local_impls = 211 traits_in_scope = 211 name = None \n                 15299ms iterate_method_candidates_dyn @ mode = MethodCall name = None traits_in_scope_len = 211 \n                   15299ms iterate_method_candidates_with_autoref @ name = None  (2 calls)\n                     15299ms iterate_method_candidates_by_receiver @ name = None  (6 calls)\n                       15299ms run_in_snapshot (12 calls)\n                         15226ms iterate_trait_method_candidates @ name = None  (13 calls)\n                           15162ms trait_solve_query @ detail = "SubscriberExt"  (658 calls)\n                             15161ms solve  @ krate = Idx::<CrateData>(354) block = None  (658 calls)\n'
[ERROR][2025-03-05 14:02:12] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'   19352ms semantic_diagnostics\n     19351ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1929ms diagnostics @ name = None  (8 calls)\n   19352ms semantic_diagnostics\n     19352ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1929ms diagnostics @ name = None  (8 calls)\n   19352ms semantic_diagnostics\n     19352ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1929ms diagnostics @ name = None  (8 calls)\n   19352ms semantic_diagnostics\n     19351ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1929ms diagnostics @ name = None  (8 calls)\n   19352ms semantic_diagnostics\n     19352ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1929ms diagnostics @ name = None  (8 calls)\n   19352ms semantic_diagnostics\n     19352ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1929ms diagnostics @ name = None  (8 calls)\n        1756ms mir_body_query @ detail = "compute_multilinear_quotients"  (3 calls)\n          1750ms trait_solve_query @ detail = "Copy"  (63 calls)\n            1750ms solve  @ krate = Idx::<CrateData>(354) block = None  (63 calls)\n   19373ms handle_inlay_hints\n     19373ms inlay_hints\n       16651ms SemanticsImpl::analyze_impl (449 calls)\n   19373ms handle_inlay_hints\n     19373ms inlay_hints\n       16651ms SemanticsImpl::analyze_impl (449 calls)\n        1276ms trait_solve_query @ detail = "Iterator"  (11 calls)\n          1276ms solve  @ krate = Idx::<CrateData>(354) block = None  (11 calls)\n   19373ms handle_semantic_tokens_full_delta\n     19373ms highlight\n        8730ms NameClass::classify (197 calls)\n          8730ms SemanticsImpl::analyze_impl (141 calls)\n        6710ms NameRefClass::classify @ name_ref = NameRef { syntax: NAME_REF@3..8 }  (878 calls)\n          6699ms SemanticsImpl::analyze_impl (870 calls)\n   19352ms semantic_diagnostics\n     19352ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1929ms diagnostics @ name = None  (8 calls)\n        2239ms mir_body_query @ detail = "protocol_name"  (3 calls)\n          2238ms trait_solve_query @ detail = "Copy"  (59 calls)\n            2238ms solve  @ krate = Idx::<CrateData>(354) block = None  (59 calls)\n'
[ERROR][2025-03-05 14:02:12] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'   19389ms handle_semantic_tokens_full_delta\n     19389ms highlight\n        8730ms NameClass::classify (197 calls)\n          8730ms SemanticsImpl::analyze_impl (141 calls)\n            4681ms infer_query (2 calls)\n              2420ms resolve_obligations_as_possible (2670 calls)\n                2403ms trait_solve_query @ detail = "PartialEq"  (95 calls)\n                  2403ms solve  @ krate = Idx::<CrateData>(354) block = None  (95 calls)\n              1331ms trait_solve_query @ detail = "alias_eq"  (119 calls)\n                1330ms solve  @ krate = Idx::<CrateData>(354) block = None  (119 calls)\n        6710ms NameRefClass::classify @ name_ref = NameRef { syntax: NAME_REF@3..8 }  (878 calls)\n          6699ms SemanticsImpl::analyze_impl (870 calls)\n        1402ms run_in_snapshot (29 calls)\n          1401ms trait_solve_query @ detail = "??"  (23 calls)\n            1401ms solve  @ krate = Idx::<CrateData>(354) block = None  (23 calls)\n'
[ERROR][2025-03-05 14:02:12] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'   19352ms semantic_diagnostics\n     19352ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1929ms diagnostics @ name = None  (8 calls)\n          1693ms infer_query (6 calls)\n   19378ms handle_inlay_hints\n     19378ms inlay_hints\n       16651ms SemanticsImpl::analyze_impl (449 calls)\n         10825ms infer_query (5 calls)\n            1871ms iterate_method_candidates_dyn @ mode = MethodCall name = Some(Name { symbol: "len", ctx: () }) traits_in_scope_len = 60  (92 calls)\n              1370ms iterate_method_candidates_with_autoref @ name = Some(Name { symbol: "len", ctx: () })  (76 calls)\n                1370ms iterate_method_candidates_by_receiver @ name = Some(Name { symbol: "len", ctx: () })  (107 calls)\n                  1370ms run_in_snapshot (187 calls)\n                    1244ms iterate_trait_method_candidates @ name = Some(Name { symbol: "enumerate", ctx: () })  (126 calls)\n                      1228ms trait_solve_query @ detail = "IndexedParallelIterator"  (45 calls)\n                        1228ms solve  @ krate = Idx::<CrateData>(354) block = None  (45 calls)\n            7116ms resolve_obligations_as_possible (3992 calls)\n              6714ms trait_solve_query @ detail = "Sized"  (306 calls)\n                6713ms solve  @ krate = Idx::<CrateData>(354) block = None  (305 calls)\n            1781ms trait_solve_query @ detail = "alias_eq"  (191 calls)\n              1780ms solve  @ krate = Idx::<CrateData>(354) block = None  (190 calls)\n'
[ERROR][2025-03-05 14:02:30] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'   17631ms handle_completion\n      1598ms CompletionContext::new\n        1563ms CompletionContext::analyze\n          1563ms SemanticsImpl::analyze_impl\n            1563ms infer_query\n     15816ms import_on_the_fly_method @ potential_import_name = "" \n'
[ERROR][2025-03-05 14:02:30] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'       15814ms ImportAssets::search_for_imports\n         15814ms ImportAssets::search_for\n           15814ms ImportAssets::trait_applicable_items\n             15496ms iterate_method_candidates_with_traits\n               15496ms iterate_method_candidates_dyn @ with_local_impls = 211 traits_in_scope = 211 name = None \n                 15496ms iterate_method_candidates_dyn @ mode = MethodCall name = None traits_in_scope_len = 211 \n                   15496ms iterate_method_candidates_with_autoref @ name = None  (2 calls)\n                     15496ms iterate_method_candidates_by_receiver @ name = None  (6 calls)\n                       15496ms run_in_snapshot (12 calls)\n                         15422ms iterate_trait_method_candidates @ name = None  (13 calls)\n                           15354ms trait_solve_query @ detail = "SubscriberExt"  (658 calls)\n                             15353ms solve  @ krate = Idx::<CrateData>(354) block = None  (658 calls)\n'
[ERROR][2025-03-05 14:02:33] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	"   20833ms handle_semantic_tokens_full_delta\n     20833ms highlight\n        9350ms NameClass::classify (315 calls)\n          9350ms SemanticsImpl::analyze_impl (243 calls)\n        6865ms NameRefClass::classify @ name_ref = NameRef { syntax: NAME_REF@3..8 }  (1421 calls)\n          6854ms SemanticsImpl::analyze_impl (1394 calls)\n        1345ms run_in_snapshot (35 calls)"
[ERROR][2025-03-05 14:02:33] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'\n          1344ms trait_solve_query @ detail = "??"  (25 calls)\n            1344ms solve  @ krate = Idx::<CrateData>(354) block = None  (25 calls)\n'
[ERROR][2025-03-05 14:02:33] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'   20836ms handle_semantic_tokens_full_delta\n     20835ms highlight\n        9350ms NameClass::classify (315 calls)\n          9350ms SemanticsImpl::analyze_impl (243 calls)\n            4723ms infer_query (2 calls)\n              2447ms resolve_obligations_as_possible (2670 calls)\n                2430ms trait_solve_query @ detail = "PartialEq"  (95 calls)\n'
[ERROR][2025-03-05 14:02:33] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'                  2430ms solve  @ krate = Idx::<CrateData>(354) block = None  (95 calls)\n              1350ms trait_solve_query @ detail = "alias_eq"  (119 calls)\n                1350ms solve  @ krate = Idx::<CrateData>(354) block = None  (119 calls)\n        6864ms NameRefClass::classify @ name_ref = NameRef { syntax: NAME_REF@3..8 }  (1421 calls)\n          6854ms SemanticsImpl::analyze_impl (1394 calls)\n        1317ms run_in_snapshot (38 calls)\n          1316ms trait_solve_query @ detail = "??"  (28 calls)\n            1316ms solve  @ krate = Idx::<CrateData>(354) block = None  (28 calls)\n'
[ERROR][2025-03-05 14:02:33] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'   20868ms handle_inlay_hints\n     20866ms inlay_hints\n       17743ms SemanticsImpl::analyze_impl (845 calls)\n          2790ms infer_query (5 calls)\n            1002ms resolve_obligations_as_possible (1200 calls)\n        1551ms trait_solve_query @ detail = "Iterator"  (13 calls)\n          1551ms solve  @ krate = Idx::<CrateData>(354) block = None  (13 calls)'
[ERROR][2025-03-05 14:02:33] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	"\n"
[ERROR][2025-03-05 14:02:33] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'   20865ms handle_inlay_hints\n     20864ms inlay_hints\n       17743ms SemanticsImpl::analyze_impl (845 calls)\n          4845ms infer_query (2 calls)\n            3579ms resolve_obligations_as_possible (1420 calls)\n              3489ms trait_solve_query @ detail = "Clone"  (174 calls)\n                3489ms solve  @ krate = Idx::<CrateData>(354) block = None  (172 calls)\n   20865ms handle_inlay_hints\n     20863ms inlay_hints\n       17743ms SemanticsImpl::analyze_impl (845 calls)\n          5842ms infer_query (5 calls)\n            1068ms iterate_method_candidates_dyn @ mode = Path name = Some(Name { symbol: "zero", ctx: () }) traits_in_scope_len = 60  (51 calls)\n            3655ms resolve_obligations_as_possible (2330 calls)\n              3462ms trait_solve_query @ detail = "Clone"  (156 calls)\n                3461ms solve  @ krate = Idx::<CrateData>(354) block = None  (156 calls)\n            1112ms trait_solve_query @ detail = "Pairing"  (121 calls)\n              1112ms solve  @ krate = Idx::<CrateData>(354) block = None  (121 calls)\n'
[ERROR][2025-03-05 14:02:37] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	"   24537ms semantic_diagnostics"
[ERROR][2025-03-05 14:02:37] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'\n     24534ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1953ms diagnostics @ name = None  (8 calls)\n'
[ERROR][2025-03-05 14:02:37] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'    3702ms semantic_diagnostics\n      3699ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n'
[ERROR][2025-03-05 14:02:37] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'    3734ms semantic_diagnostics\n      3731ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n'
[ERROR][2025-03-05 14:02:37] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'    6924ms semantic_diagnostics\n      6922ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n'
[ERROR][2025-03-05 14:02:37] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'   24537ms semantic_diagnostics\n     24534ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1953ms diagnostics @ name = None  (8 calls)\n'
[ERROR][2025-03-05 14:02:37] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'   24537ms semantic_diagnostics\n     24534ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1953ms diagnostics @ name = None  (8 calls)\n          1643ms infer_query\n        2320ms mir_body_query @ detail = "eval_and_quotient_scalars"  (6 calls)\n          2319ms trait_solve_query @ detail = "Copy"  (85 calls)\n            2318ms solve  @ krate = Idx::<CrateData>(354) block = None  (85 calls)\n   24537ms semantic_diagnostics\n'
[ERROR][2025-03-05 14:02:37] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'     24534ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1952ms diagnostics @ name = None  (8 calls)\n'
[ERROR][2025-03-05 14:02:37] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'   24537ms semantic_diagnostics\n     24535ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1953ms diagnostics @ name = None  (8 calls)\n'
[ERROR][2025-03-05 14:02:37] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'   24537ms semantic_diagnostics\n     24535ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1953ms diagnostics @ name = None  (8 calls)\n        1941ms mir_body_query @ detail = "open" \n          1940ms trait_solve_query @ detail = "Copy"  (45 calls)\n            1940ms solve  @ krate = Idx::<CrateData>(354) block = None  (45 calls)\n'
[ERROR][2025-03-05 14:02:37] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'    3701ms semantic_diagnostics\n      3698ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n'
[ERROR][2025-03-05 14:02:37] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'   24537ms semantic_diagnostics\n     24534ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1952ms diagnostics @ name = None  (8 calls)\n'
[ERROR][2025-03-05 14:02:37] .../vim/lsp/rpc.lua:770	"rpc"	"/run/current-system/sw/bin/rust-analyzer"	"stderr"	'   24537ms semantic_diagnostics\n     24534ms diagnostics @ name = Some(Name { symbol: "zeromorph", ctx: () }) \n        1952ms diagnostics @ name = None  (8 calls)\n'

@g1684774 g1684774 added the C-bug Category: bug label Mar 5, 2025
@ShoyuVanilla ShoyuVanilla added A-completion autocompletion A-perf performance issues labels Mar 6, 2025
@ShoyuVanilla
Copy link
Member

Autocompletions are generally slow because they iterate and check through the trait items for completion candidates. But I think that we could/should improve the performance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion autocompletion A-perf performance issues C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants