-
Notifications
You must be signed in to change notification settings - Fork 170
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
Ruby LSP Indexing is very slow on version 0.19.0 #2671
Comments
Thank you for the report. I think this is likely related to the fact that we started handling multibyte characters correctly in #2619. While I understand that the slow down is not ideal, it's a cost we have to pay to handle non ASCII characters used in Ruby appropriately. For ASCII-only sources, there are optimizations we apply to ensure better performance, but calculating the appropriate code unit locations for multibyte sources is expensive by nature. And we must do it during indexing otherwise users of multibyte characters will get features offset by an incorrect number of bytes, like developers using Japanese characters as part of their Ruby code. Are you using a lot of multibyte characters in your codebase? For example, characters with accents like |
This is a new codebase I am working on, it big and I still don't know it very well yet. But I don't think we have a lot of non ASCII characters. It's an application for USA market only, everything is in English. It is taking a bit more than 4 minutes to index. |
@jmschp I'd be curious to see the times for v0.18.4 vs v0.19.0. (You can temporarily add |
I used the following Regular Expression Times:
|
That's a crazy increase. You're not indexing tests by any chance? Do you use |
I use I have the |
Did you already exclude the spec directory from indexing? If not, can you please try this and let us know if indexing is faster? We should probably exclude {
"rubyLsp.indexing": {
"excludedPatterns": ["**/spec/**.rb"],
},
} |
Hey! I faced the same issue, indexing time increased from 7 seconds on v0.18.4 to 32 seconds on v0.19.1 😞 I excluded the spec directory, but it didn't help. |
There's definitly some time being spend one something. I added some logging and here are my worst offenders: /home/earlopain/.rbenv/versions/3.3.5/lib/ruby/3.3.0/prism/node.rb
38.29374
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/prism-1.1.0/lib/prism/inspect_visitor.rb
0.57227
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundler/vendor/fileutils/lib/fileutils.rb
0.53581
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/addressable-2.8.7/lib/addressable/uri.rb
0.4459
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/3.3.0/fileutils.rb
0.38042
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/parser-3.3.5.0/lib/parser/lexer-F0.rb
0.16495
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/parser-3.3.5.0/lib/parser/ruby32.rb
0.15025
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/prism-1.1.0/lib/prism/node.rb
0.08192
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/prism-1.1.0/lib/prism/serialize.rb
0.06388
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/parser-3.3.5.0/lib/parser/ruby31.rb
0.05073 Most are done very quickly but there's definitly at least one outlier, taking 38 (!) seconds. With 0.18.4: /home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/parser-3.3.5.0/lib/parser/lexer-F1.rb
0.13788
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/3.3.0/rubygems/vendor/resolv/lib/resolv.rb
0.07309
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/parser-3.3.5.0/lib/parser/lexer-F0.rb
0.05923
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/parser-3.3.5.0/lib/parser/ruby23.rb
0.04744
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/parser-3.3.5.0/lib/parser/ruby31.rb
0.04695
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/parser-3.3.5.0/lib/parser/ruby19.rb
0.04603
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/parser-3.3.5.0/lib/parser/ruby33.rb
0.04545
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/prism-1.1.0/lib/prism/node.rb
0.04175
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/3.3.0/prism/node.rb
0.04161
/home/earlopain/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/parser-3.3.5.0/lib/parser/ruby26.rb
0.03907 It's still in the Top10 but nowhere near as bad. Overall things seem to be taking longer. I guess Edit: I missed this initially, the file taking so long is the one from prism shipped with ruby by default. The one from the gem (I have it it my dependencies) finishes very quickly in both cases. It used to contain a bunch of non-ascii characters for pretty-printing the ast, which is now part of a different file. ruby/prism@0f21f5b If I read the code right, it will |
I had not excluded the |
For me on 0.19 it gets stuck always at 66% for several minutes (10+), although it eventually finished. I tried again with 0.18.4 and
The lsp log did not seem to provide much information, just:
|
Just an update: we're looking into how we can compute code unit lengths in a more performant way. I'd really like to avoid reverting the multibyte support since it allows developers who write comments in other languages (like Japanese) to have a correct experience using the Ruby LSP. If we can't fix it in a timely manner, we will revert and re-evaluate. |
Hi, I'm sorry to hear that the performance has deteriorated due to the multi-byte character support. I haven't been able to reproduce the issue in my local codebase and thus haven't been able to fully verify it, but would it be possible to modify it as follows? The Currently, because it converts from the beginning of the file to the relevant position, the processing efficiency deteriorates as the file size increases. I thought we might be able to achieve speedup by comparing the encoding of the source with the encoding of the argument, and skipping the conversion if they are the same. |
Not happening anymore with |
Awesome! |
I can also confirm that is it much faster in the 0.20.0. Thank you! |
Description
Ruby LSP Information
VS Code Version
1.91.1
Ruby LSP Extension Version
0.8.2
Ruby LSP Server Version
0.19.0
Ruby LSP Addons
Ruby Version
3.3.5
Ruby Version Manager
asdf
Installed Extensions
Click to expand
Ruby LSP Settings
Click to expand
Workspace
User
Reproduction steps
Code snippet or error message
The text was updated successfully, but these errors were encountered: