ruby-lsp: Ruby LSP Indexing is very slow on version 0.19.0

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 LSP Rails

Ruby Version

3.3.5

Ruby Version Manager

asdf

Installed Extensions

Click to expand
  • better-comments (3.0.2)
  • cucumberautocomplete (3.0.5)
  • vscode-erb-beautify (0.5.0)
  • pyright (1.1.327)
  • vscode-zipfs (3.0.0)
  • vscode-markdownlint (0.56.0)
  • vscode-eslint (3.0.10)
  • dotenv-vscode (0.28.1)
  • gitlens (15.5.1)
  • prettier-vscode (11.0.0)
  • vscode-pull-request-github (0.92.0)
  • todo-tree (0.0.226)
  • vscode-drawio (1.6.6)
  • prettier-sql-vscode (1.6.0)
  • haml (1.4.1)
  • mongodb-vscode (1.7.0)
  • vscode-docker (1.29.2)
  • debugpy (2024.6.0)
  • python (2024.12.3)
  • vscode-pylance (2024.8.1)
  • cpptools (1.21.6)
  • cpptools-extension-pack (1.3.0)
  • cpptools-themes (2.0.0)
  • vscode-versionlens (1.14.2)
  • material-icon-theme (5.11.1)
  • platformio-ide (3.3.3)
  • vscode-xml (0.27.1)
  • vscode-yaml (1.15.0)
  • trailing-spaces (0.4.1)
  • ruby-lsp (0.8.2)
  • code-spell-checker (4.0.13)
  • code-spell-checker-portuguese-brazilian (2.2.1)
  • vscode-stylelint (1.4.0)
  • highlight-matching-tag (0.11.0)
  • markdown-all-in-one (3.6.2)

Ruby LSP Settings

Click to expand
Workspace
{}
User
{
  "enableExperimentalFeatures": false,
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": true,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": true,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": true,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true
  },
  "featuresConfiguration": {},
  "addonSettings": {},
  "rubyVersionManager": {
    "identifier": "asdf"
  },
  "customRubyCommand": "",
  "formatter": "auto",
  "linters": null,
  "bundleGemfile": "",
  "testTimeout": 30,
  "branch": "",
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "",
  "indexing": {},
  "erbSupport": true
}

Reproduction steps

  1. Open VS Code
  2. Ruby LSP starts indexing
  3. On this new version (0.19.0) Indexing is a whole lot slower! 😢 It starts to slow down at 30% on my case.

Code snippet or error message

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 16 (9 by maintainers)

Most upvoted comments

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.

For me on 0.19 it gets stuck always at 66% for several minutes (10+)…

Not happening anymore with 0.20.0 🎉

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 prism/node.rb contains some special characters but the file is so large and I didn’t find any from scrolling through.

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. https://github.com/ruby/prism/commit/0f21f5bfe1e4a1753c5ddb88b73ffaa6ea641a0c

If I read the code right, it will dup the source code from the beginning all the way to the token it is currently looking at which is just horrible for performance the larger the file is.

@andyw8

I used the following Regular Expression [^\x00-\x7f] to search the code base, and found 64 results in 9 Ruby files.

Times:

  • 0.18.4 -> 0′44″
  • 0.19.0 -> 4′12″ 😢