Conversation
dduugg
left a comment
There was a problem hiding this comment.
PR Review: "Vendor speedscope with gem"
Goal
Resolves #35. Bundle a pre-built speedscope release directly into the gem so users don't need Node.js/npx at runtime. Falls back to npx speedscope if the vendored copy is absent.
Implementation
Rakefile: Adds aspeedscope:vendortask that downloads the speedscope release ZIP from GitHub, unpacks it intovendor/speedscope/, and hooks intorake buildso it runs automatically. Aspeedscope:clobbertask cleans it up.lib/singed/speedscope.rb(new): ASinged::Speedscopemodule encapsulating version constant, path detection, and two open strategies — vendored (no Node) and npx fallback.lib/singed/flamegraph.rb:openandopen_commanddelegate toSinged::Speedscopeinstead of hardcodingnpx.singed.gemspec:vendor/speedscope/**/*added tospec.filesso it ships with the gem.Gemfile/Gemfile.lock:rubyzipadded as a dev dependency for ZIP extraction during the build task..gitignore:vendor/speedscopeignored (it's downloaded at build time, not checked in).
Risk Assessment
Low–Medium risk overall. A few things worth flagging:
1. open_command and open are inconsistent (potential confusion)
open_command builds a URL with #localProfilePath=<profile_path> pointing at the profile directly:
"#{os_open_command} file://#{bundled_index_html}#localProfilePath=#{profile_path}"But open_with_bundled_speedscope writes a .js file and uses #localProfilePath=<js_path> pointing at the JS file instead. These two methods describe different behaviors, which is confusing and means open_command (used for the user-facing log message) doesn't match what open actually does.
2. Spaces and special characters in paths not escaped
open_command interpolates profile_path directly into a shell string without quoting:
"#{os_open_command} file://#{bundled_index_html}#localProfilePath=#{profile_path}"Paths with spaces will break the command. The open method uses system(cmd, arg) form (safe), but open_command would be unsafe if passed to system directly.
3. rubyzip is a dev dependency but is required in Rakefile
rubyzip is added to Gemfile but not to the gemspec's add_development_dependency. This is fine since it's only needed by maintainers doing rake build, but worth a clarifying comment for contributors.
4. Gem size increase is significant but acknowledged
~10 kB → ~230 kB. Reasonable tradeoff for eliminating the Node.js requirement, and clearly noted in the PR.
5. Pinned to speedscope 1.24.0 due to upstream issue
1.25.0 doesn't include the ZIP artifact (upstream issue). Worth tracking — bump to 1.25.0+ once the upstream issue is resolved.
6. No tests for the new Singed::Speedscope module
The new module has meaningful branching logic (vendored vs. npx path, OS detection, HTML wrapper for macOS/Windows) with no spec coverage. Worth adding at minimum unit tests for open_command and the OS detection logic.
Summary
Solid, well-scoped improvement. Main items before merging:
- Fix the inconsistency between
open_command(useslocalProfilePath=<profile>) andopen(useslocalProfilePath=<js_file>) - Add specs for
Singed::Speedscope - Consider quoting paths in
open_commandfor robustness - Add a TODO to bump to speedscope 1.25.0+ once the upstream ZIP issue is resolved
Seems that specifying dev dependencies in gemspec is kind of obsolete and not really used in the wild: everything goes to the See discussions at ruby/rubygems#7799 and rubocop/rubocop#11469
Added a note to the speedscope version constant
Added a spec |
PR Review (Updated): "Vendor speedscope with gem"GoalResolves #35. Bundle a pre-built speedscope release directly into the gem so users don't need Node.js/npx at runtime. Falls back to What's Been Addressed Since the Last Review
Remaining Issues
|
| @@ -0,0 +1,81 @@ | |||
| # frozen_string_literal: true | |||
There was a problem hiding this comment.
| # frozen_string_literal: true | |
| # frozen_string_literal: true |
(minor, but i think this may actually impact freezing)
Resolves #35
On gem release (via
rake build) download built speedscope release and put it intovendor/speedscope. If there is no speedscope there for some reason, fallback to npx as before.Caution
It makes built gem to increase in weight from ≈10kB to ≈230kB
Warning
Although latest speedscope release at the moment is 1.25.0 it doesn't include archive for built speedscope for some reason, so I set it to 1.24.0 for now. See jlfwong/speedscope#546