Project

General

Profile

« Previous | Next » 

Revision 6ad0f89d

Added by Eregon (Benoit Daloze) over 1 year ago

[ruby/prism] Use a more efficient StringIO on TruffleRuby

  • The stdlib StringIO is synchronized and this occurs a high overhead.
  • This is about twice as fast on TruffleRuby but surprisingly it is slower on JRuby.
    I am not sure why but probably @ivar access and integer arithmetic
    is much slower than Java field access/arithmetic on JRuby.
  • On CRuby interpreter it is slower, which is expected as the GVL already protects StringIO.
  • So we enable this only on TruffleRuby to not slow down other Rubies.
  • PRISM_FFI_BACKEND=true ruby -v -Ilib -rprism -rbenchmark -e '300.times { p Benchmark.realtime { Dir.glob("lib/**/*.rb") { |f| Prism.parse_file(f) } } }'
    ruby 3.3.0: 0.215 => 0.251 (cext: 0.062)
    ruby 3.3.0 YJIT: 0.118 => 0.113 (cext: 0.053)
    truffleruby JVM: 0.101 => 0.054
    jruby 9.4.6.0: 0.162 => 0.219
    jruby 9.4.6.0 indy: 0.078 => 0.086
  • For the record here are the numbers for using the String directly, without a StringIO-like object:
    ruby 3.3.0: 0.215 => 0.234 (cext: 0.062)
    ruby 3.3.0 YJIT: 0.118 => 0.111 (cext: 0.053)
    truffleruby native: 0.101 => 0.053
    jruby 9.4.6.0: 0.162 => 0.195
    jruby 9.4.6.0 indy: 0.078 => 0.082
    As we can see, that extra object adds a non-trivial overhead on CRuby interpreter and JRuby.
    But we need to make it possible to use StringIO and SimpleStringIO interchangeably.

https://github.com/ruby/prism/commit/938677cbd2