Skip to content

Commit

Permalink
Replace RipperRubyParser with Prism for DescendantLoader
Browse files Browse the repository at this point in the history
RipperRubyParser isn't really maintained anymore whereas Prism is
soon becoming the replacement official Ruby parser. Prism already has a
RubyParser translation layer internally, which is fully maintained.
Additionally, the performance of Prism is much faster than Ripper.

Performance testing DescendantLoader:

Cached sti_loader? | Measurement            | Time (s)
------------------ | ---------------------- | ---------------------
(Ripper) No cache  | Vm.descendants         | 15.303
(Prism)  No cache  | Vm.descendants         |  4.093 (73% faster)
(Ripper) No cache  | evm:compile_sti_loader | 20.120
(Prism)  No cache  | evm:compile_sti_loader |  8.216 (59% faster)
(Ripper) Cached    | Vm.descendants         |  0.554
(Prism)  Cached    | Vm.descendants         |  0.583 (same)
(Ripper) Cached    | evm:compile_sti_loader |  3.271
(Prism)  Cached    | evm:compile_sti_loader |  3.138 (same)
  • Loading branch information
Fryguy committed Apr 26, 2024
1 parent 2d5ecbd commit 14a7757
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ gem "openscap", "~>0.4.8", :require => false
gem "optimist", "~>3.0", :require => false
gem "pg", ">=1.4.1", :require => false
gem "pg-dsn_parser", "~>0.1.1", :require => false
gem "prism", ">=0.25.0", :require => false # Used by DescendantLoader
gem "psych", ">=3.1", :require => false # 3.1 safe_load changed positional to kwargs like aliases: true: https://github.com/ruby/psych/commit/4d4439d6d0adfcbd211ea295779315f1baa7dadd
gem "query_relation", "~>0.1.0", :require => false
gem "rack", ">=2.2.6.4", :require => false
Expand All @@ -71,7 +72,6 @@ gem "rails", "~>6.1.7", ">=6.1.7.7"
gem "rails-i18n", "~>6.x"
gem "rake", ">=12.3.3", :require => false
gem "rest-client", "~>2.1.0", :require => false
gem "ripper_ruby_parser", "~>1.11", :require => false
gem "ruby-progressbar", "~>1.7.0", :require => false
gem "rubyzip", "~>2.0.0", :require => false
gem "rugged", "~>1.5.0", :require => false
Expand Down
5 changes: 2 additions & 3 deletions lib/extensions/descendant_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ def self.status(io = $stdout)
# be defined in [depending on runtime details], the name of the class,
# and the name of its superclass), given a path to a ruby script file.
module Parser
autoload :RipperRubyParser, 'ripper_ruby_parser'
autoload :Prism, 'prism'

def classes_in(filename)
content = File.read(filename)
begin
parsed = RipperRubyParser::Parser.new.parse(content, filename)
parsed = Prism::Translation::RubyParser.parse_file(filename)
rescue => e
warn "\nError parsing classes in #{filename}:\n#{e.class.name}: #{e}\n\n"
raise
Expand Down

0 comments on commit 14a7757

Please sign in to comment.