kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.61k stars 112 forks source link

Significant performance issue in LSP resolver #1493

Closed logo749 closed 2 months ago

logo749 commented 2 months ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. Open a big .k, with thousand nesting config
  2. The LSP will in resolver stage forever

2. What did you expect to see? (Required)

  1. LSP resolver end in reasonable time

3. What did you see instead (Required)

  1. LSP resolver run forever

4. What is your KCL components version? (Required)

0.9.0

I found the problem is in the walk_config_entries of the resolver process:

kcl-main/kclvm/sema/src/resolver/config.rs line: 521 image

walk_config_entries will travel all children twice, cause a child node be visited 2 * (parent count) count. In a deep tree, will become a big performance issue. In my case is a 2w+ line .k, 20+ depth

My question is:

  1. Is this expected behavior?
  2. Can I use the ty in node_ty_map, instead of travel all children again?
Peefy commented 2 months ago

@logo749 Good Catch! 👍 PRs are also welcome. ❤️

cc @He1pa Can you help answer or troubleshoot the problem?

He1pa commented 2 months ago

Thanks for your feedback, I solved the issue of visiting the node twice in #1498. And we track the overall performance issues of LSP in #1237