Skip to content

Slower than CRuby while parsing files through YARP/Prism gem #3293

@faraazahmad

Description

@faraazahmad

I've got a file where I'm trying to parallely parse all the Ruby files in the discourse codebase.

require 'parallel'
require 'prism'
require 'benchmark'

GLOB = '/Users/faraaz/oss/discourse/**/*.rb'

def bench
    Parallel.each(Dir.glob(GLOB), in_threads: 8) do |file|
        Prism.parse_file(file)
    end
end

Benchmark.bm do |x|
    x.report("Attempt 1") { bench }
    x.report("Attempt 2") { bench }
    x.report("Attempt 3") { bench }
end

I am also using the Prism and Parallel gem to do so. Here's my Gemfile.lock:

GEM
  remote: https://rubygems.org/
  specs:
    parallel (1.23.0)
    prism (0.13.0)

PLATFORMS
  x86_64-darwin

DEPENDENCIES
  parallel (~> 1.23)
  prism (~> 0.13.0)

BUNDLED WITH
   2.4.13

I ran this code using CRuby 3.3.0-preview1, truffleruby-23.0.0 (native) truffleruby-23.1.0 (native). Here are the results:

ruby 3.3.0preview1 (2023-05-12 master a1b01e7701) [x86_64-darwin22]

       user     system      total        real
Attempt 1  1.849014   0.270058   2.119072 (  2.136894)
Attempt 2  1.823381   0.245018   2.068399 (  2.070048)
Attempt 3  1.781599   0.245300   2.026899 (  2.028847)

---
truffleruby 23.0.0, like ruby 3.1.3, Oracle GraalVM Native [x86_64-darwin]

       user     system      total        real
Attempt 1 61.490037  11.793482  73.283519 ( 14.299126)
Attempt 2 47.419287  12.269673  59.688960 ( 11.679390)
Attempt 3 37.302392  14.540728  51.843120 ( 10.538771)

---
truffleruby 23.1.0, like ruby 3.2.2, Oracle GraalVM Native [x86_64-darwin]

       user     system      total        real
Attempt 1 60.098041  11.371509  71.469550 ( 14.642849)
Attempt 2 48.722091  13.202782  61.924873 ( 12.418994)
Attempt 3 48.938087  11.993571  60.931658 ( 12.815382)

I threw in the GraalVM version for good measure and it seemed to be JIT compiling pretty well but is still slower than CRuby.

truffleruby 23.1.0, like ruby 3.2.2, Oracle GraalVM JVM [x86_64-darwin]

       user     system      total        real
Attempt 1 92.124363  11.339075 103.463438 ( 14.062655)
Attempt 2 46.448333   9.770680  56.219013 (  7.803680)
Attempt 3 43.827920  10.542195  54.370115 (  7.585570)
Attempt 4 42.939988  10.571172  53.511160 (  7.550312)
Attempt 5 41.170301  10.427718  51.598019 (  7.432247)
Attempt 6 41.673918  10.460389  52.134307 (  7.421614)

TruffleRuby seems considerably slower than CRuby in these benchmarks. Is this a bug?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions