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

Solve your problem, speed up your life, and paint it black with Ruby!

Solve your problem, speed up your life, and paint it black with Ruby!

Slides for Rakuten Technology Conference 2013 talk "Solve your problem, speed up your life, and paint it black with Ruby!" http://tech.rakuten.co.jp/

Akira Matsuda

October 26, 2013
Tweet

More Decks by Akira Matsuda

Other Decks in Programming

Transcript

  1. Ruby is different today. I hear every programmer say •Ruby

    is a "web language" •Ruby is a "slow language"
  2. I use Ruby because... •I'm a web programmer. •Every web

    programmer uses Rails. •Ruby is the language "under Rails".
  3. Why Ruby? •Rails is my business... and business is good!

    •I'm not playing on Ruby, I'm just working on Rails.
  4. New trolls! •Submit a CFP titled "7 reasons why Ruby

    is slow" for a Ruby conference. Immediately. •Be quick, or be dead you'll miss a chance to get up on stage.
  5. 7 reasons? •They say GC is slow. •They say Ruby

    is slow because of the "GIL" thing.
  6. "GIL" (or GVL) • What exactly is it? • Don't

    ask me. I don't know. Ask @_ko1 or @kosaki55tea • No, actually you need not to know about it. • I hear every programmer say JRuby or Rubinius are better and faster than MRI because they are GIL free. So let's just throw MRI away.
  7. GIL free! •Thank Matz Almighty, we are free at last!

    •Roll over @yotii23's husband, tell Patch Monster the news.
  8. Concurrency is such a lonely word. Every Thread is so

    untrue. array = [] 5.times.map do Thread.new do 1000.times do array << nil end end end.each(&:join) puts array.size http://www.jstorimer.com/blogs/workingwithcode/8085491-nobody-understands-the-gil
  9. Concurrency is hardly ever heard. And mostly what we need

    from Ruby. •% ruby -v thread_tes.rb ruby 2.1.0dev (2013-10-14 trunk 43282) [x86_64-darwin12.5.0] 5000 •% ruby -v thread_tes.rb rubinius 2.1.1 (2.1.0 be67ed17 2013-10-18 JI) [x86_64-darwin12.5.0] 3504
  10. OMG

  11. But ... but I still feel like Ruby is kind

    of slow for me, so what can I do?
  12. No trolls! •Submit a CFP titled "7 reasons why Ruby

    is slow" for a Ruby conference. Immediately.
  13. Don't troll. Code. • Unless you're a VM programmer, shut

    your mouth. • That's @_Ko1's business. • That's why Heroku pays @_ko1's salary. • Instead, nd a problem that YOU can deal with. • And don't let it be. Don't whisper words of wisdom. Solve it.
  14. I know a person who actually have been doing this

    •He thought Rails is slow because assets are slow. •=> The asset pipeline •He thought Rails is slow because we are reloading assets for every request. •=> Turbolinks
  15. Your Rails app is slow because... •Kernel#require is slow •RubyGems

    & Bundler is slow •ActiveRecord is slow •RSpec is slow •Rack is slow
  16. 'Cause I try and I try and I try and

    I try • Before: % time rails r 1 4.07s user 1.32s system 95% cpu 5.650 total % time rails r 1 3.91s user 1.15s system 99% cpu 5.087 total % time rails r 1 3.91s user 1.17s system 99% cpu 5.107 total • After: % time rails r 1 4.20s user 1.24s system 99% cpu 5.467 total % time rails r 1 3.98s user 1.17s system 99% cpu 5.167 total % time rails r 1 3.99s user 1.15s system 99% cpu 5.169 total
  17. Hail, hail to Bundler •It turned out that RubyGems rewrites

    Kernel#require and makes it slow, but Bundler re- rewrites it and makes it fast nally.
  18. 10% of `time rake spec` was spent for DB cleaning

    •time rake spec: 14m01s •time spent on cleaning DB: 77m35s
  19. lazy-load partials •Separate a huge webpage into several partials. Then

    load the partials via separate requests. •Rails views already have "partials". •What if partials are lazy-load- able?
  20. Can't they be squashed into one lib/ directory? •Because each

    gem are basically namespaced. •The only thing that looks good on me, at runtime, is lib/ directory in most cases.
  21. Current directory structure ᵓᴷᴷ gem1 ᴹ ᵋᴷᴷ lib >> LOAD_PATH

    ᴹ ᵓᴷᴷ gem1 ᴹ ᴹ ᵓᴷᴷ bar.rb ᴹ ᴹ ᵋᴷᴷ foo.rb ᴹ ᵋᴷᴷ gem1.rb ᵋᴷᴷ gem2 ᵋᴷᴷ lib >> $LOAD_PATH ᵋᴷᴷ gem2 ᵓᴷᴷ fuga.rb ᵋᴷᴷ hoge.rb
  22. Squash all gems into one directory ᵋᴷᴷ all_bundled_gems_in_one ᵋᴷᴷ lib

    >> LOAD_PATH ᵓᴷᴷ gem1 ᴹ ᵓᴷᴷ bar.rb ᴹ ᵋᴷᴷ foo.rb ᵓᴷᴷ gem1.rb ᵋᴷᴷ gem2 ᵓᴷᴷ fuga.rb ᵋᴷᴷ hoge.rb
  23. Problems I'm willing to challenge •Make Haml faster •Or create

    a faster fork of Haml •Make ActiveRecord faster •Or create a faster subset of AR
  24. Finder.app •Mr. Finder.app, what went down in your head •Your

    UI to me seems so tragic, with the thrill of it all
  25. At Railsษڧձ@౦ژ last month •We talked about how Finder.app sucks

    •We agreed that we need a better " ler" •And I started creating it last month.
  26. Productivity • It's so hard to do simple things such

    as `mkdir`, `rm`, or `cd` to a hidden directory. • How can I `touch`? How can I `ln -s`? How can I `chmod`? • Telling me more and more about some useless features. Supposed to : re: my productivity.
  27. Do ya think I'm sexy? •This tool is not very

    glamorous but still very sexy.
  28. What a drag it is getting old •Am I sticking

    to an old tool that I'm used to because I'm too old to learn new tools? •No. I'm creating this not just for nostalgy but for productivity.
  29. Concept, design •FD + Vim •Simple MVC •M: les &

    directories •V: Curses •C: logic •Customizable, plugin-able architecture
  30. Implementation •Basically commands are one- char •Each command is de

    ned as a method in commands.rb •Pressing a key simply runs that method (send)
  31. Summary (1) •I use Ruby to solve "my" problem •OSS

    != volunteering. No need to "contribute" to someone else. Start with "your" problem. It's a very good place to start.
  32. Summary (2) •Ruby is slow, and I'm trying to make

    it faster. •You can do it even if you're not a VM hacker or a GC hacker. •There're many unoptimized parts left in the whole Rails app stack.
  33. Conclusion •Play with Ruby for fun rather than just work

    with Ruby for money! •Let's spend the night with Ruby!