Hal Fulton: Future of Ruby

History of Ruby

"Java will be the COBOL of the early 21st century."
Perl(6).kill?(Ruby(2.0)) # => false

"When Perl 6 gets here, it will still have many of the disadvantages of being Perl."

Larry Wall's said publicly that Perl 6 will borrow heavily from Ruby.


Andrea Wright: Games with Ruby

  ships with nifty little graphics thingies
  bouncing, tetris, alpha blending, etc.
  setVideoMode sets everything off to start with
  openGL not well-integrated with Ruby API
  typical physics bouncey stuff in Sprite class
  steven davidovitz' nebular gauntlet:
    simple particle engines
    asteroids with alpha stuff and good graphics
    console interface (!)

  dead, but good ideas and interesting resources
  more Rubyish API for SDL
  Ruby/SDL setVideoMode returns DisplaySurface object
  RUDL uses DisplaySurface.new, etc.
  RUDL has less direct mapping, and apparently less access to defaults and constants
  more readability, less power? (tradeoffs)
    set Z 0 for 2-D

  high-level with wrappers on SDL
  initially based on PyGame
  Rects - little grid thingies
    give it inflate(-x) and it deflates
    totally Pythonic
  Polygons (stuff) and Boundaries (space)

  catch(:quit) do
    loop do

  polished and compact
  teh complete
  includes really well thought out tutorial
  Window class (gasp!) instead of Rects or Boundaries
  seems to work mainly by overriding predefined callbacks
    kinda Railsy that way

  def draw
    @other_things.each {|thing| thing.draw}

  idiomatic Ruby
  seems niftiest library so far
  Escave - volcano lava splat game
  silly platform scroller where you feed sleep-walking witch chili, ice cream, chocolate
  ASCII tiles (ascii boxes) to define levels
    chars map to sprites/objects
  newly added: support for ImageMagick
    morphing and stuff

  written in C++
  uses SWIG
  has a native Ruby feel

  sprites + ImageMagick = acid tetris?

GGZ Gaming Zone Project
  portal or something

  3D modelling
  Ruby wrapper around 3D modelling thing
  smoke, lighting, 3D modelling package
  testing framework for 3D modelling
    how crazy is that?
  Shattered Ruby - Ogre wrapper based on Rails (wtf?!)
    similar MVC shit
    making assumptions about views, file locations, formats, etc.
    :x.to_v # => Symbol#to_vector
    timers are what makes Shattered tick
    Rails: app/models, app/views, test/units, etc.
    RMaterials modelling files with ERb
      Shattered-compatible physics engine
      scene_manager, camera, viewport, timer, space :gravity => :blahblahblah  
    Shattered can drop to Ogre the same way ARec can drop to SQL
    Shattered forces GC with each frame
    easy to export from Blender
  giant bee


Ezra Z on Ruby Performance
  Performance dichotomy
    Beautiful code slow / Reasonably pretty code fast
    Web apps, bottleneck usually DB or network
  benchmarking on idioms
  Symbol#to_proc "a little Perlish-looking"
    also way slow compared to regular code
  benchmarked on a million iterations
    def foo
    def bar &proc
  Ruby interpreter heavily optimized for yield, not #call
  equivalent code with each or inject: inject twice as slow
  =~ vs. match() # => =~ faster, much faster when match succeeds
    "tongue" operator
    overhead of creating a MatchData object
    re = /foo/o # => pre-compilation; actually slower than regular regexes
  method call overhead in Ruby surprisingly expensive
  "a lot of this stuff is fixed in Rubinius"
  :send slower than direct invocation
  regular args instead of options hashes - significantly faster
  "most of the stuff that's expensive in Matz's Ruby is expensive in JRuby"
  benchmarking is definitely the key
  eval() really expensive due to new abstract syntax trees, nested interpreting essentially
    suggested no-eval pragma
      enables a lot of optimizations that depend on eval()'s absence
  benchmarking produces efficient coding habits

  "profiling - measure, don't guess"
  sudo gem install ruby-prof
  result = RubyProf.profile do
    helper profiler allows you to plug in ruby-prof on Merb code Ez wants to profile
    obviously adaptable to Rails or other frameworks
      gives it args saying "show me anything which takes more than X amount of time"
  auto-generates reporting

  Merb - result of hosting many Rails apps
    Rails gives Ruby bad name for being slow as Rails uses some slowish idioms
    not bagging on Rails
    metaprogramming slower than regular programming
      metaprogramming frenzy in Rails community slows stuff down
    Merb started out as Mongrel handler + Erb

    cgi.rb => ugliest piece of code in the Ruby standard library

    Merb basically a performance-oriented alternative to ActionPack

    Mutex-conservative, as opposed to Rails, which is more sort of Mutex-greedy
      Rails did it because making a thread-safe framework only helps when client programmers write thread-safe apps

    Merb 2x - 3x faster than Rails on average
    short stack traces
    Favor simple code over magic code
    Rails cultural convention of metaprogramming and then metaprogramming somebody else's metaprogramming:
      result is very deep call stacks
      (specifically, sequences of alias_method_chain calls)
    Rails actions seemed unRubyish, so he made renders just the return values of actions in Merb
      can return any IO object that responds to read
        (how insanely cool is that?)
      very useful with Object#to_json
      very fast by avoiding rendering chain
    "No code is faster than no code"
      "simplicity and clarity trumps magic every time"
    Merb plugin architecture: gems
      nice and simple

    Merb is about 6,000 lines of code
      "big fan of hacker-friendly frameworks"
      smaller, slimmer, more flexible, no one golden path

    "Rubinius IS going to be the new Ruby"
      based on Smalltalk
      anyone who knows Ruby can work on core Rubinius
    trunk Merb two times faster than current release
      Merb gets faster
      Rails gets slower
    Merb uses RSpec but has open-ended handlers that allow you to use Test::Unit if you want
    open-door SVN policy (like Rubinius)
    "Rails ripoff"

    Merb by itself only uses 10 or 12MB of RAM

  (huge difference between def foo and define_method :foo
    slower to define, slower to call as well
    3 times slower
      not in Rubinius!
    because of the closure
  "ActiveRecord objects are quite expensive to instantiate"
    memory overhead
    slow definition
    slow calling
    one extra :include in a :find can up Mongrel memory usage by 100MB)

  back to Merb:
      more complex schemas
      defaults to ActiveRecord patterns
    identity map cache in memory - won't re-create or re-obtain if it already has a copy
    transactional object memory

    cool mode for IRB: debug-compiler
    rubinius assembly
    bytecodes (optional)
  Ruby -> Rubinius assembly code -> bytecode