Shopify / ruby-lsp

An opinionated language server for Ruby
https://shopify.github.io/ruby-lsp/
MIT License
1.51k stars 140 forks source link

Add in-editor profiling with Vernier #2273

Open vinistock opened 2 months ago

vinistock commented 2 months ago

It would be amazing if we could profile a given Ruby script/executable using vernier and then show the results inside of the editor.

VS Code doesn't have profiling APIs yet and I'm not sure if this is planned or not. Which means we need to build everything custom. However, we may be able to show the generated webpage that you'd normally view in the Firefox profiler view within a VS Code webview.

vinistock commented 1 month ago

I took a quick stab at this and managed to get most of it working. Branch.

Currently, that branch defines a task to profile the current file opened in the editor and adds a button on the editor navigation for convenience. After running the script with Vernier, it will then open a web view just showing the profile's JSON content.

The part missing is the visualization, for which we have two options:

  1. Generate the HTML using the Firefox profile viewer (or some other tool) and then put that HTML in the web view
  2. According to the JavaScript performance profiling docs, it seems that VS Code has native support for .cpuprofile and .heapprofile files, which automatically get handled with table or flamegraph views.

From a maintenance and DX standpoint, I would prefer number 2. That would mean that Ruby profiles are treated the same as JavaScript ones - keeping consistency. And we wouldn't need any implementation or extra dependencies because it's baked in VS Code already.

However, I do not know if these cpuprofile and heapprofile extensions are applicable to Ruby. And even if they are, it does not look like Vernier supports either of those yet. Need to do some more research.