Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Truffle] while loops not being optimized? #3308

Closed
brauliobo opened this issue Sep 4, 2015 · 9 comments
Closed

[Truffle] while loops not being optimized? #3308

brauliobo opened this issue Sep 4, 2015 · 9 comments
Milestone

Comments

@brauliobo
Copy link

Under jt irb, I ran this abc method a few times:

def abc; count = 0; while(count < 100000000); count = count + 1; end; puts count; end

And it took ages to finish. Under MRI 2.2.3 it takes 2.6s.

Is there some optimization I'm missing? I have configured export JAVACMD=graalvm-jdk1.8.0/bin/java and can see this on the irb's process.

@eregon
Copy link
Member

eregon commented Sep 4, 2015

If you use jt, you can pass --graal to run with graal without specifying JAVACMD yourself.

Running from a file works more reliably:

require 'benchmark'
def abc
  count = 0
  while count < 100000000
    count = count + 1
  end
  puts count
end
5.times { puts Benchmark.measure { abc } }

# run with jt ruby --graal test.rb

But there seems to currently be a bug with On-Stack-Replacement (a relatively new feature) + background compilation, which sometimes just aborts the JIT and then runs in the interpreter.

One way to currently make it work reliably in IRB is to disable background compilation:

jt ruby --graal -J-G:-TruffleBackgroundCompilation -S irb

@brauliobo
Copy link
Author

@eregon I still must be doing something wrong.

First, I've recompiled jruby using the JAVACMD of graalvm, as before I did compiled with the system openjdk. Is that necessary? Anyway, it didn't made any difference.

Then I copied your code into

~/P/o/jruby git:master ❯❯❯ jt ruby --graal -J-G:-TruffleBackgroundCompilation -S irb
$ JAVACMD=/home/braulio/Projects/others/jruby/graalvm-jdk1.8.0/bin/java /home/braulio/Projects/others/jruby/bin/jruby -X+T -Xtruffle.core.load_path=truffle/src/main/ruby -J-server -J-G:-TruffleBackgroundCompilation -S irb

And the results were:

100000000
 60,640000   0,190000  60,830000 ( 59,710326)
100000000
 61,480000   0,190000  61,670000 ( 60,562418)
100000000
 61,110000   0,170000  61,280000 ( 60,200459)
100000000
 60,270000   0,210000  60,480000 ( 59,239121)
100000000
 60,690000   0,260000  60,950000 ( 59,979416)

So no real improvements yet.

@eregon
Copy link
Member

eregon commented Sep 4, 2015

@brauliobo Compilation of JRuby is fine with any javac >= 1.7, so it's not needed.

Which version of Graal did you download? 0.7?

Could you try running from a file? IRB is not an ideal environment for benchmarks.
If that is still slow, can you try with:

jt ruby --graal -J-G:+TraceTruffleCompilationDetails -J-G:-TruffleBackgroundCompilation test.rb
# or if you want for IRB:
jt ruby --graal -J-G:+TraceTruffleCompilationDetails -J-G:-TruffleBackgroundCompilation -S irb

@brauliobo
Copy link
Author

@eregon graal version 0.8 (openjdk-8-graalvm-b132-linux-x86_64-0.8.tar.gz)

Runned jt ruby --graal -J-G:+TraceTruffleCompilationDetails -J-G:-TruffleBackgroundCompilation -S test.rb putting the same source on test.rb, and got the same results:

$ JAVACMD=/home/braulio/Projects/others/jruby/graalvm-jdk1.8.0/bin/java /home/braulio/Projects/others/jruby/bin/jruby -X+T -Xtruffle.core.load_path=truffle/src/main/ruby -J-server -J-G:+TraceTruffleCompilationDetails -J-G:-TruffleBackgroundCompilation -S test.rb
100000000
 60,110000   0,230000  60,340000 ( 58,566378)
100000000
 62,320000   0,080000  62,400000 ( 60,785585)
100000000
 60,400000   0,110000  60,510000 ( 59,364598)
100000000
 60,770000   0,110000  60,880000 ( 59,886292)
100000000
 62,110000   0,130000  62,240000 ( 61,201530)

@eregon
Copy link
Member

eregon commented Sep 4, 2015

@brauliobo We are using Graal 0.7 on the master branch, so you need that version instead.
I would have expected we throw an error on an incompatible Graal version but apparently it's pretty quiet in this case. We'll fix that.

Can you try with Graal 0.7?

@brauliobo
Copy link
Author

ok, worked now! sorry for the misunderstading

~/P/o/jruby git:master ❯❯❯ jt ruby --graal -J-G:+TraceTruffleCompilationDetails -J-G:-TruffleBackgroundCompilation -S test.rb                                         ◼
$ JAVACMD=/home/braulio/Projects/others/jruby/graalvm-jdk1.8.0/bin/java /home/braulio/Projects/others/jruby/bin/jruby -X+T -Xtruffle.core.load_path=truffle/src/main/ruby -J-server -J-G:+TraceTruffleCompilationDetails -J-G:-TruffleBackgroundCompilation -S test.rb
[truffle] opt queued       Fixnum#<(core):core: Fixnum#< <split-7-U>                   |ASTSize       6/    6 |Calls/Thres    1000/    3 |CallsAndLoop/Thres    1000/ 1000 |Inval#              0 
[truffle] opt start        Fixnum#<(core):core: Fixnum#< <split-7-U>                   |ASTSize       6/    6 |Calls/Thres    1000/    3 |CallsAndLoop/Thres    1000/ 1000 |Inval#              0 
[truffle] opt done         Fixnum#<(core):core: Fixnum#< <opt> <split-7-U>             |ASTSize       6/    6 |Time   380( 326+54  )ms |DirectCallNodes I    0/D    0 |GraalNodes    28/   27 |CodeSize          173 |Source core: Fixnum#< 
[truffle] opt queued       Fixnum#+(core):core: Fixnum#+ <split-4-U>                   |ASTSize       7/    7 |Calls/Thres    1000/    3 |CallsAndLoop/Thres    1000/ 1000 |Inval#              0 
[truffle] opt start        Fixnum#+(core):core: Fixnum#+ <split-4-U>                   |ASTSize       7/    7 |Calls/Thres    1000/    3 |CallsAndLoop/Thres    1000/ 1000 |Inval#              0 
[truffle] opt done         Fixnum#+(core):core: Fixnum#+ <opt> <split-4-U>             |ASTSize       7/    7 |Time   370( 110+259 )ms |DirectCallNodes I    0/D    0 |GraalNodes    26/   95 |CodeSize          329 |Source core: Fixnum#+ 
[truffle] opt start        test.rb:4<OSR>                                              |ASTSize      24/   24 |Calls/Thres       0/    3 |CallsAndLoop/Thres       0/ 1000 |Inval#              0 
[truffle] opt queued       test.rb:4<OSR>                                              |ASTSize      24/   24 |Calls/Thres       0/    3 |CallsAndLoop/Thres       0/ 1000 |Inval#              0 
[truffle] opt done         test.rb:4<OSR> <opt>                                        |ASTSize      24/   37 |Time   321( 283+38  )ms |DirectCallNodes I    2/D    0 |GraalNodes    77/  116 |CodeSize          297 |Source            n/a 
100000000
  4,550000   0,050000   4,600000 (  1,506278)
100000000
  0,560000   0,000000   0,560000 (  0,271986)
100000000
  0,590000   0,000000   0,590000 (  0,266338)
100000000
  0,600000   0,000000   0,600000 (  0,278580)
100000000
  0,320000   0,000000   0,320000 (  0,292983)

@eregon
Copy link
Member

eregon commented Sep 4, 2015

Great!
No problem, we should make the Graal version requirement clearer.

@chrisseaton
Copy link
Contributor

@brauliobo if you are experimenting with Truffle, join us in #jruby on IRC or https://gitter.im/jruby and if you are in a EU or US time zone there will normally be someone there who can help you in real time.

@chrisseaton chrisseaton added this to the truffle-dev milestone Sep 6, 2015
@brauliobo
Copy link
Author

thanks @chrisseaton!

I've messaged you on #jruby channel. The gitter room is private.

I willing to fix some easy to fix failing specs on jruby+truflle.

@enebo enebo added this to the Non-Release milestone Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants