castwide / vscode-solargraph

A Visual Studio Code extension for Solargraph.
Other
425 stars 23 forks source link

Autocompletion is instantaneous, but go to definition is very slow #236

Open 64kramsystem opened 2 years ago

64kramsystem commented 2 years ago

Hello,

I'm working on a relatively small project (8k Ruby lines, according to cloc v1.90; only a few dependent gems). I've documented all the methods in the project (the vast majority with @return [void], and some with actual param/return types).

With this setup, autocompletion is essentially immediate. It fully works as intended: the plugin is aware of the given instance type, and shows the accessible methods list (in turn, each method shows a window with the reference to the class+method, and the method documentation).

The problem is that the "Go to defiition", for the very same instance, is instead very slow; it generally uses 100% of the CPU for several seconds each time, making it unsuitable for usage on a laptop, besides making it hardly usable in general.

Something I've also observed is that the time taken is actually - sometimes it jumps immediately, but after jumping to a few other methods, even if nothing in the project changed, it takes again a long time. It behaves like there was a sort of "hot methods cache" that is busted after going to a few method definitions.

Is such slowness expected? It's counterintuitive to me - without knowing the internals - that autocompletion shows complete (metadata) knowledge of a given method, but actually jumping to the method is extremely slow in comparison.

===

Regarding the configuration:

64kramsystem commented 2 years ago

I've found the overall behavior to be odd; it seems Solargraph (and/or the VSC plugin) gets "clogged" when "Go to definition" is issued. I'll describe a couple of examples.

Base code (extreme simplification of the original):

class Runtime
  # @param location [TemporaryVariable, Fisk::Operand, Integer]
  # @return [void]
  def jump(location)
    # blah
  end

  # @return [Fisk::Operand]
  def return_value
    # blah
  end
end

rt = Runtime.new
rt.jump rt.return_value

First case:

Second case:

Is there any way to debug vscode-solargraph and/or solargraph, to profile how the time is spent?

castwide commented 2 years ago

I looked into this, and the the "go to defintion" request definitely seems slower than it should be. I'll keep this on the radar and look for a solution.