Rubinius For You - GoRuCo

82
Rubinius For You Evan Phoenix Jun 4th, 2011 @evanphx github.com/evanphx

description

Evan Phoenix' presentation at GoRuCo

Transcript of Rubinius For You - GoRuCo

Page 1: Rubinius For You - GoRuCo

Rubinius For You

Evan Phoenix Jun 4th, 2011

★ @evanphx ♘ github.com/evanphx

Page 2: Rubinius For You - GoRuCo

The Year Rubinius Breaks Through

2011

Page 3: Rubinius For You - GoRuCo

Why Bother?

Page 4: Rubinius For You - GoRuCo

We can have it better

Why Bother?

Page 5: Rubinius For You - GoRuCo

Not a single release, a philosophy

Why Bother?

Page 6: Rubinius For You - GoRuCo

Improve over time

Why Bother?

Page 7: Rubinius For You - GoRuCo

Improve

Performance

Why Bother?

Page 8: Rubinius For You - GoRuCo

Improve

Tooling

Why Bother?

Page 9: Rubinius For You - GoRuCo

Improve

Developer Experience

Why Bother?

Page 10: Rubinius For You - GoRuCo

What’s Next?

Page 11: Rubinius For You - GoRuCo

2.0

What’s Next?

Page 12: Rubinius For You - GoRuCo

2.0

Ruby 1.9 support

What’s Next?

Page 13: Rubinius For You - GoRuCo

2.0

Concurrency

What’s Next?

Page 14: Rubinius For You - GoRuCo

2.0

Microsoft Windows support

What’s Next?

Page 15: Rubinius For You - GoRuCo

Real World

Page 16: Rubinius For You - GoRuCo

When programs stop being polite and start getting real.

Real World

Page 17: Rubinius For You - GoRuCo

Rubinius slower than it should be

Real World

Page 18: Rubinius For You - GoRuCo

Profiling is key to improving

Real World

Page 19: Rubinius For You - GoRuCo

Profiling is key to improving

Example

Real World

Page 20: Rubinius For You - GoRuCo

WARNING:SCIENCE AHEAD

Page 21: Rubinius For You - GoRuCo

A method seems slow

Problem:

Page 22: Rubinius For You - GoRuCo

Step 1

Improving

Page 23: Rubinius For You - GoRuCo

Step 1

Benchmark

Improving

Page 24: Rubinius For You - GoRuCo

require 'benchmark'cc = CoworkersCode.new

Benchmark.bm do |x| x.report("initial") { cc.calculate_awesome_score }end

Page 25: Rubinius For You - GoRuCo

user system total realinitial 0.071788 0.001601 0.073389 ( 29.998823)

Page 26: Rubinius For You - GoRuCo

user system total realinitial 0.071788 0.001601 0.073389 ( 29.998823)

Page 27: Rubinius For You - GoRuCo

29.998823

Page 28: Rubinius For You - GoRuCo

user: 0.071788system: 0.001601 total: 0.073389 real: 29.998823

Page 29: Rubinius For You - GoRuCo

Time running code

User

Page 30: Rubinius For You - GoRuCo

Time inside the kernel

System

Page 31: Rubinius For You - GoRuCo

Sum of user and system

Total

Page 32: Rubinius For You - GoRuCo

Elapsed wall clock

Real

Page 33: Rubinius For You - GoRuCo

Topic

Wall Clock

Page 34: Rubinius For You - GoRuCo

user: 0.071788system: 0.001601 total: 0.073389 real: 29.998823

Page 35: Rubinius For You - GoRuCo

0.073389

29.998823!=??

Page 36: Rubinius For You - GoRuCo

Step 2

Profile

Improving

Page 37: Rubinius For You - GoRuCo

» rbx -Xprofile scratch/profile_sample.rb

% cumulative self self total time seconds seconds calls ms/call ms/call name------------------------------------------------------------ 99.69 30.00 30.00 10 3000.10 3000.10 Rubinius::Channel#receive_timeout 0.13 0.04 0.04 2 19.82 19.82 IO.open_with_mode 0.11 0.03 0.03 1 33.05 33.05 IO::Buffer#fill 0.02 0.01 0.01 18 0.30 0.30 FFI::Platform::POSIX.stat

Page 38: Rubinius For You - GoRuCo

» rbx -Xprofile -Xprofiler.graph scratch/profile_sample.rb

0.00 30.00 10/60 Kernel#sleep [15][16] 99.9 30.00 0.00 10 Rubinius::Channel#receive_timeout [16]

0.00 30.00 10/20 CoworkersCode#superhero_factor [14][15] 99.9 0.00 30.00 10 Kernel#sleep [15] 30.00 0.00 10/10 Rubinius::Channel#receive_timeout [16]

Page 39: Rubinius For You - GoRuCo

def superhero_factor sleep 3 rand(10) end

Page 40: Rubinius For You - GoRuCo

Step 3

Fix and benchmark

Improving

Page 41: Rubinius For You - GoRuCo

user system total realinitial 0.000102 0.000047 0.000149 ( 0.000139)

Page 42: Rubinius For You - GoRuCo

0.000139

Page 43: Rubinius For You - GoRuCo

0.073389

29.998823!=

Page 44: Rubinius For You - GoRuCo

Invisible in all but real

Sleep!

Page 45: Rubinius For You - GoRuCo

A method seems slow

Problem:

SOLVED!

Page 46: Rubinius For You - GoRuCo

Rubinius can tune your code itself

Real World

Page 47: Rubinius For You - GoRuCo

Rubinius can tune your code itself

Dynamic is not dynamic all the time

Real World

Page 48: Rubinius For You - GoRuCo

“It’s ducks all the way down.”

- Sandi Metz

Page 49: Rubinius For You - GoRuCo

Rubinius can tune your code itself

Most of yours quack the same though!

Real World

Page 50: Rubinius For You - GoRuCo

def last_part(str) str.split(“ “).lastend

Page 51: Rubinius For You - GoRuCo

def last_part(str) str.split(“ “).lastend

Page 52: Rubinius For You - GoRuCo

21%

1 class98%

1: 25245 2: 275 3: 86 4: 50 5: 35 6: 6 7: 10 8: 5 9: 5 10: 2 10+: 34

Call sites running Array specs

Page 53: Rubinius For You - GoRuCo

Rubinius can tune your code itself

Shoot first, let the VM sort it out.

Real World

Page 54: Rubinius For You - GoRuCo

Made for ruby applications

Real World

Page 55: Rubinius For You - GoRuCo

Made for ruby applications

Ruby is objects

Real World

Page 56: Rubinius For You - GoRuCo

Made for ruby applications

Rubinius is made for objects

Real World

Page 57: Rubinius For You - GoRuCo

Made for ruby applications

Lots of objects

Real World

Page 58: Rubinius For You - GoRuCo

“To optimize, I make sure not to create objects.”

- Ryan Smith

Page 59: Rubinius For You - GoRuCo

1. 10,000,000 timesa. Create 101 objectsb. Save one of them

https://gist.github.com/1008305

Page 60: Rubinius For You - GoRuCo

0

500

1000

1500

2000

2500

3000

MBs

mri

Page 61: Rubinius For You - GoRuCo

1. 10,000,000 timesa. Create 101 objectsb. Save one of them

Saved objects: 10,000,000

Page 62: Rubinius For You - GoRuCo

0

500

1000

1500

2000

2500

3000

MBs

mri rbx

Page 63: Rubinius For You - GoRuCo

0

50

100

150

200

250

300

MBs

mri rbx

Page 64: Rubinius For You - GoRuCo

0

12

23

35

47

58

70

100k 200k 300k 400k

MBs

mri rbx

Page 65: Rubinius For You - GoRuCo

0

750

1,500

2,250

3,000

mri rbx

57

531

Memory Time

Page 66: Rubinius For You - GoRuCo

Made for ruby applications

Love thy objects

Real World

Page 67: Rubinius For You - GoRuCo

Next Steps

Page 68: Rubinius For You - GoRuCo

More profiling, more tuning

Next Steps

Page 69: Rubinius For You - GoRuCo

Newer, smarter compiler

Next Steps

Page 70: Rubinius For You - GoRuCo

Rubinius and You

Page 71: Rubinius For You - GoRuCo

Compatibly is there

Rubinius and You

Page 72: Rubinius For You - GoRuCo

Rubinius isn’t terrible for any workload

Rubinius and You

Page 73: Rubinius For You - GoRuCo

Rubinius is amazing for some

Rubinius and You

Page 74: Rubinius For You - GoRuCo

Try Rubinius!

Rubinius and You

Page 75: Rubinius For You - GoRuCo

Stickers in the back!

Rubinius and You

Page 77: Rubinius For You - GoRuCo

Use it in production=>

blog post about you

Rubinius Reward

Page 78: Rubinius For You - GoRuCo

Thanks!

Evan Phoenix Jun 4th, 2011

★ @evanphx ♘ github.com/evanphx

Page 79: Rubinius For You - GoRuCo

Technology

Efficient Memory Layout

Rubinius

Page 80: Rubinius For You - GoRuCo

obj.ivars = { :@name => “Evan”, :@age => 31}

Page 81: Rubinius For You - GoRuCo

obj.class.ivars = { :@name => 0, :@age => 1}

obj.ivars = [ “Evan”, 31]

Page 82: Rubinius For You - GoRuCo

Flags

Class

Extra Ivars

@name

@age