Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Try JIT compiler for Ruby 2.6

Try JIT compiler for Ruby 2.6

Meguro.rb#13 で「Ruby の JIT を触ってみた話」をしました
cf. https://megurorb.connpass.com/event/82076/

Nao Minami

March 28, 2018
Tweet

More Decks by Nao Minami

Other Decks in Technology

Transcript

  1. ©2018 Wantedly, Inc. 3VCZͷ+*5Λࢼͯ͠ΈΔ $ rbenv install --list | grep

    2.6 1.8.6-p286 1.9.3-p286 2.2.6 2.6.0-dev 2.6.0-preview1 rbx-2.2.6 rbx-2.6 $ rbenv install 2.6.0-preview1 $ rbenv global 2.6.0-preview1 QSFWJFXΛSCFOWͰJOTUBMM
  2. ©2018 Wantedly, Inc. 3VCZͷ+*5Λࢼͯ͠ΈΔ +PIO)BXUIPSOϒϩάͷCFODIΛࢼ͢ IUUQTXXXKPIOIBXUIPSODPNQMBZJOHXJUISVCZKJUNKJU def calculate(a, b, n

    = 40_000_000) n.times.count do a = a * 16807 % 2147483647 b = b * 48271 % 2147483647 (a & 0xffff) == (b & 0xffff) end end raise unless calculate(65, 8921) == 588 p result: calculate(699, 124)
  3. ©2018 Wantedly, Inc. $ ruby tmp/bench.rb {:result=>600} ruby tmp/playing.rb 10.68s

    user 0.12s system 97% cpu 11.084 total $ ruby --disable-gems --jit tmp/bench.rb {:result=>600} ruby --disable-gems --jit tmp/playing.rb 8.12s user 0.13s system 103% cpu 7.973 total 3VCZͷ+*5Λࢼͯ͠ΈΔ +*5ͰTT΁վળʂʂ
  4. ©2018 Wantedly, Inc. $ ruby --disable-gems --jit --jit-verbose=2 tmp/bench.rb MJIT:

    CC defaults to clang MJIT: tmp_dir is … Creating precompiled header Starting process: clang clang -w -O3 -emit-pch -o ….h.gch …/rb_mjit_min_header-2.6.0.h start compile: block in calculate@tmp/bench.rb:2 -> ….c Starting process: clang clang -dynamic -bundle -O3 -include-pch ….h.gch -o …/ _ruby_mjit_p23579u0.bundle ….c -L…/lib -Wl,-undefined,dynamic_lookup -Wl,- multiply_defined,suppress JIT success (195.0ms): block in calculate@tmp/bench.rb:2 -> ….c {:result=>600} Canceling pch and worker threads Successful MJIT finish ruby --disable-gems --jit --jit-verbose=2 tmp/bench.rb 8.59s user 0.14s system 102% cpu 8.480 total 3VCZͷ+*5Λࢼͯ͠ΈΔ AŠKJUWFSCPTFAΦϓγϣϯΛ͚࣮ͭͯߦ DPNQJMF։࢝
  5. ©2018 Wantedly, Inc. $ ruby --disable-gems --jit --jit-verbose=2 tmp/bench.rb MJIT:

    CC defaults to clang MJIT: tmp_dir is … Creating precompiled header Starting process: clang clang -w -O3 -emit-pch -o ….h.gch …/rb_mjit_min_header-2.6.0.h start compile: block in calculate@tmp/bench.rb:2 -> ….c Starting process: clang clang -dynamic -bundle -O3 -include-pch ….h.gch -o …/ _ruby_mjit_p23579u0.bundle ….c -L…/lib -Wl,-undefined,dynamic_lookup -Wl,- multiply_defined,suppress JIT success (195.0ms): block in calculate@tmp/bench.rb:2 -> ….c {:result=>600} Canceling pch and worker threads Successful MJIT finish ruby --disable-gems --jit --jit-verbose=2 tmp/bench.rb 8.59s user 0.14s system 102% cpu 8.480 total 3VCZͷ+*5Λࢼͯ͠ΈΔ AŠKJUWFSCPTFAΦϓγϣϯΛ͚࣮ͭͯߦ NTͰDPNQJMFऴྃ
  6. ©2018 Wantedly, Inc. $ ruby --jit --jit-verbose=2 tmp/bench.rb . .

    . . ruby --jit --jit-verbose=2 tmp/bench.rb 12.67s user 0.73s system 148% cpu 9.055 total 3VCZͷ+*5Λࢼͯ͠ΈΔ ͪͳΈʹAŠEJTBCMFHFNTAΦϓγϣϯΛ֎͢ ͱɻɻɻʁ ෆཁͳDPNQJMF͕૸ͬͯΉ͠Ζ஗͘ͳΔ