Slide 1

Slide 1 text

How people build software ! " Make Rails Great Again A @tenderlove Guide to Things

Slide 2

Slide 2 text

How people build software ! HELLO!!!! 2 !

Slide 3

Slide 3 text

How people build software ! Aaron Patterson 3 !

Slide 4

Slide 4 text

How people build software ! @tenderlove 4 !

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

How people build software ! Ruby Core Team Rails Core Team 6 !

Slide 7

Slide 7 text

How people build software ! Ruby Security Team Rails Security Team 7 !

Slide 8

Slide 8 text

How people build software ! PGP Fingerprint: 4CE9 1B75 A798 28E8 6B1A A8BB 9531 70BC B4FF AFC6 8 !

Slide 9

Slide 9 text

How people build software ! #2 Committer 9 !

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

How people build software ! GitHub 11 !

Slide 12

Slide 12 text

How people build software ! Le Git 12 !

Slide 13

Slide 13 text

How people build software ! GitHug 13 !

Slide 14

Slide 14 text

Plain old slides

Slide 15

Slide 15 text

Sponsored Talk

Slide 16

Slide 16 text

Brought to you by @ihavenotea

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

I have stickers of my cats

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

My Job at GitHub

Slide 24

Slide 24 text

GitHub: How people build software

Slide 25

Slide 25 text

Bringing GitHub Application Development to Everyone

Slide 26

Slide 26 text

Rails Core Develompent

Slide 27

Slide 27 text

Ruby Core Development

Slide 28

Slide 28 text

Buy our products!

Slide 29

Slide 29 text

My Career Goals

Slide 30

Slide 30 text

I wanted to get rich.

Slide 31

Slide 31 text

Why?

Slide 32

Slide 32 text

So that I could do what I want. (Which is making Rails great again)

Slide 33

Slide 33 text

Become a Cog

Slide 34

Slide 34 text

I want to be a cog!

Slide 35

Slide 35 text

New in Rails 5

Slide 36

Slide 36 text

Rails is in it’s Prime 5

Slide 37

Slide 37 text

No more XML situps

Slide 38

Slide 38 text

JSON burpees

Slide 39

Slide 39 text

Threading

Slide 40

Slide 40 text

Race Condition VROOOOM!!!!

Slide 41

Slide 41 text

Le Mans is just Nascar for Europe Follow @ juliancheal today! (He gave me this joke) Advertisement:

Slide 42

Slide 42 text

Ruby Drama

Slide 43

Slide 43 text

I am extremely angry at Jeremy

Slide 44

Slide 44 text

Friday, April 22, 2016 7:57 pm

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

JEREMY!!!

Slide 47

Slide 47 text

5

Slide 48

Slide 48 text

5

Slide 49

Slide 49 text

$5

Slide 50

Slide 50 text

$5 footlong

Slide 51

Slide 51 text

WHAT EVEN IS THIS?

Slide 52

Slide 52 text

Ruby on Rails The mainstream }The Surplus of Slides

Slide 53

Slide 53 text

I ❤ u JD!

Slide 54

Slide 54 text

Major Changes in ActiveRecord

Slide 55

Slide 55 text

I want to talk about SQL

Slide 56

Slide 56 text

So I’ve prepared a statement Follow @ kerrizor today! ❤ Advertisement:

Slide 57

Slide 57 text

ApplicationRecord

Slide 58

Slide 58 text

Appealing to Startups

Slide 59

Slide 59 text

Application Generation [aaron@TC rails (master)]$ ruby railties/exe/rails new ~/git/omglolwut2 --dev --skip-bundle create create README.md create Rakefile create config.ru create .gitignore create Gemfile create app create app/assets/config/manifest.js create app/assets/javascripts/application.js create app/assets/javascripts/cable.js create app/assets/stylesheets/application.css create app/channels/application_cable/channel.rb create app/channels/application_cable/connection.rb create app/controllers/application_controller.rb create app/helpers/application_helper.rb create app/jobs/application_job.rb create app/mailers/application_mailer.rb create app/models/application_record.rb create app/models/business.rb create app/views/layouts/application.html.erb create app/views/layouts/mailer.html.erb create app/views/layouts/mailer.text.erb create app/assets/images/.keep create app/assets/javascripts/channels create app/assets/javascripts/channels/.keep create app/controllers/concerns/.keep create app/models/concerns/.keep create bin create bin/bundle create bin/rails create bin/rake create bin/setup create bin/update create config create config/routes.rb create config/application.rb create config/environment.rb create config/secrets.yml create config/cable.yml create config/puma.rb om glolwut2

Slide 60

Slide 60 text

Application Generation create app/controllers/application_controller.rb create app/helpers/application_helper.rb create app/jobs/application_job.rb create app/mailers/application_mailer.rb create app/models/application_record.rb create app/models/business.rb create app/views/layouts/application.html.erb create app/views/layouts/mailer.html.erb

Slide 61

Slide 61 text

Business Model [aaron@TC rails (master)]$ cd ~/git/omglolwut2 [aaron@TC omglolwut2]$ cat app/models/business.rb class Business < ApplicationRecord # Business model end [aaron@TC omglolwut2]$

Slide 62

Slide 62 text

This is a HackerNews compliant business model

Slide 63

Slide 63 text

Surprises!

Slide 64

Slide 64 text

PHP templates

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

5

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

We need to go further

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

Lets get down to business

Slide 71

Slide 71 text

What have you done for me lately?

Slide 72

Slide 72 text

Yes, but what have you done for me *lately*?

Slide 73

Slide 73 text

Performance

Slide 74

Slide 74 text

SURPRISE!!! GitHub: You can put code there! Advertisement:

Slide 75

Slide 75 text

I ❤ Performance

Slide 76

Slide 76 text

Topics Boot Time Performance Run Time Performance Memory Efficiency

Slide 77

Slide 77 text

Performance is always about tradeoffs

Slide 78

Slide 78 text

Memory for speed

Slide 79

Slide 79 text

Concurrency for memory

Slide 80

Slide 80 text

Complexity for memory

Slide 81

Slide 81 text

Performance is never free

Slide 82

Slide 82 text

Always understand your constraints.

Slide 83

Slide 83 text

Boot Time Performance leftpad-ng.js: for all your padding needs, but only on the left side Advertisement:

Slide 84

Slide 84 text

bundle exec rails s RubyGems Bundler Rails Rails

Slide 85

Slide 85 text

bundle exec rails s RubyGems Bundler Rails Rails

Slide 86

Slide 86 text

Speeding up Ruby speeds up everything.

Slide 87

Slide 87 text

But that doesn’t mean we should write slow code.

Slide 88

Slide 88 text

Two Optimizations Ruby (sort of) RubyGems

Slide 89

Slide 89 text

Run an empty program [aaron@TC ~]$ ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15] [aaron@TC ~]$ time ruby -e' ' real 0m0.101s user 0m0.061s sys 0m0.032s OMG RUBY IS SLOW

Slide 90

Slide 90 text

Without RubyGems [aaron@TC ~]$ ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15] [aaron@TC ~]$ time ruby -e' ' real 0m0.101s user 0m0.061s sys 0m0.032s [aaron@TC ~]$ time ruby --disable-gems -e' ' real 0m0.051s user 0m0.022s sys 0m0.023s

Slide 91

Slide 91 text

Measurement by Elimination

Slide 92

Slide 92 text

Placing blame is difficult git blame: for all your blame placing needs Advertisement:

Slide 93

Slide 93 text

gem_prelude.rb

Slide 94

Slide 94 text

Gem Prelude if defined?(Gem) require 'rubygems.rb' begin require 'did_you_mean' rescue LoadError end if defined?(DidYouMean) end Load Rubygems

Slide 95

Slide 95 text

Why load RubyGems? [aaron@TC ~]$ ruby -e'require "rubygems"; require "rails"' [aaron@TC ~]$ ruby -e'require "rails"' Bad old days of Ruby 1.8 Ruby 1.9+

Slide 96

Slide 96 text

Gem Prelude if defined?(Gem) require 'rubygems.rb' begin require 'did_you_mean' rescue LoadError end if defined?(DidYouMean) end Load Rubygems did_you_mean New in Ruby 2.3!

Slide 97

Slide 97 text

Did you mean? [aaron@TC ~]$ ruby -e'Object.new.object_ip' -e:1:in `': undefined method `object_ip' for # (NoMethodError) Did you mean? object_id [aaron@TC ~]$ I see you’re trying to call a method!

Slide 98

Slide 98 text

did_you_mean is a gem

Slide 99

Slide 99 text

Gem Prelude if defined?(Gem) require 'rubygems.rb' begin require 'did_you_mean' rescue LoadError end if defined?(DidYouMean) end did_you_mean

Slide 100

Slide 100 text

# RubyGems's require: TL;DR alias :original_require :require def require file original_require file rescue LoadError found_gem = all_gems.find do |gem| gem.contains?(file) || gem.contains?(file + ".rb") || gem.contains?(file + ".so") # .bundle on OS X, .dll on Windows end if found_gem found_gem.activate # mutates $LOAD_PATH original_require file else raise "idk lol" end end RubyGems’ Require O(3N) or just O(N)

Slide 101

Slide 101 text

The more gems installed, the slower `require` gets

Slide 102

Slide 102 text

The more gems installed, the slower `ruby` gets.

Slide 103

Slide 103 text

Watch the O(N) $ sudo dtrace -q -n \ 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' \ -c`rbenv which ruby`" -e '\ '"

Slide 104

Slide 104 text

Run it! [aaron@TC ~]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" -e '\ '" | wc -l 298 [aaron@TC ~]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" -- disable-did_you_mean -e '\ '" | wc -l 12 [aaron@TC ~]$ sudo dtrace -q -n 'syscall::stat*:entry { printf("%s\n", copyinstr(arg0)); }' -c`rbenv which ruby`" -- disable-gems -e '\ '" | wc -l 5 [aaron@TC ~]$ With RubyGems Without did_you_mean Without Both

Slide 105

Slide 105 text

File Stats actioncable-5.0.0.beta2/lib/did_you_mean actioncable-5.0.0.beta2/lib/did_you_mean.rb actioncable-5.0.0.beta2/lib/did_you_mean.bundle actionmailer-5.0.0.beta2/lib/did_you_mean actionmailer-5.0.0.beta2/lib/did_you_mean.rb actionmailer-5.0.0.beta2/lib/did_you_mean.bundle actionpack-5.0.0.beta2/lib/did_you_mean actionpack-5.0.0.beta2/lib/did_you_mean.rb actionpack-5.0.0.beta2/lib/did_you_mean.bundle actionview-5.0.0.beta2/lib/did_you_mean actionview-5.0.0.beta2/lib/did_you_mean.rb actionview-5.0.0.beta2/lib/did_you_mean.bundle activejob-5.0.0.beta2/lib/did_you_mean activejob-5.0.0.beta2/lib/did_you_mean.rb activejob-5.0.0.beta2/lib/did_you_mean.bundle

Slide 106

Slide 106 text

File Stats actioncable-5.0.0.beta2/lib/did_you_mean actioncable-5.0.0.beta2/lib/did_you_mean.rb actioncable-5.0.0.beta2/lib/did_you_mean.bundle actionmailer-5.0.0.beta2/lib/did_you_mean actionmailer-5.0.0.beta2/lib/did_you_mean.rb actionmailer-5.0.0.beta2/lib/did_you_mean.bundle actionpack-5.0.0.beta2/lib/did_you_mean actionpack-5.0.0.beta2/lib/did_you_mean.rb actionpack-5.0.0.beta2/lib/did_you_mean.bundle actionview-5.0.0.beta2/lib/did_you_mean actionview-5.0.0.beta2/lib/did_you_mean.rb actionview-5.0.0.beta2/lib/did_you_mean.bundle activejob-5.0.0.beta2/lib/did_you_mean activejob-5.0.0.beta2/lib/did_you_mean.rb activejob-5.0.0.beta2/lib/did_you_mean.bundle Why stat file with no extension?

Slide 107

Slide 107 text

GOOD NEWS EVERYONE

Slide 108

Slide 108 text

"d" is pretty early in the alphabet!

Slide 109

Slide 109 text

To speed up Rails, let us rename it to AAARails

Slide 110

Slide 110 text

Improvement

Slide 111

Slide 111 text

Use `gem` $ cat test.rb require "did_you_mean" $ sudo sh count_syscalls.sh | wc -l 299 $ cat test.rb gem "did_you_mean" require "did_you_mean" $ sudo sh count_syscalls.sh | wc -l 16 Bare `require` `gem` + `require`

Slide 112

Slide 112 text

Why this is faster: def gem gem_name spec = load_specfile(gem_name + ".gemspec") spec.activate # mutates the load path end # RubyGems's require: TL;DR alias :original_require :require def require file original_require file rescue LoadError found_gem = all_gems.find do |gem| gem.contains?(file) || gem.contains?(file + ".rb") || gem.contains?(file + ".so") # .dylib on OS X, .dll on Windows end if found_gem found_gem.activate # mutates $LOAD_PATH original_require file else raise "idk lol" end end O(1) O(1)* *Not actually O(1)

Slide 113

Slide 113 text

Fix gem_prelude.rb diff --git a/gem_prelude.rb b/gem_prelude.rb index 3f171d1..be9c419 100644 --- a/gem_prelude.rb +++ b/gem_prelude.rb @@ -1,7 +1,8 @@ if defined?(Gem) require 'rubygems.rb' begin + gem 'did_you_mean' require 'did_you_mean' - rescue LoadError + rescue Gem::LoadError, LoadError end if defined?(DidYouMean) end

Slide 114

Slide 114 text

Bare Require: O(N) Gem + Require: O(1)

Slide 115

Slide 115 text

Tradeoffs: Complexity for Speed

Slide 116

Slide 116 text

Complexity does have overhead

Slide 117

Slide 117 text

bundle exec rails s RubyGems Bundler Rails Rails Probably want the bundler gem

Slide 118

Slide 118 text

`bundle` before RG 2.5.2 [aaron@TC ~]$ tail -3 `rbenv which bundler` gem 'bundler', version load Gem.bin_path('bundler', 'bundler', version) [aaron@TC ~]$ O(1)

Slide 119

Slide 119 text

RG >= 2.5.2, < 2.6.2 [aaron@TC ~]$ tail -3 `rbenv which bundler` end load Gem.bin_path('bundler', 'bundler', version) [aaron@TC ~]$ (N)

Slide 120

Slide 120 text

bundle exec rails s RubyGems Bundler Rails Rails

Slide 121

Slide 121 text

New Technology!!!!* *Not actually new

Slide 122

Slide 122 text

Startup Time 12% 13% 34% 41% Compilation Execution Searching GC These Are Not Actual Times

Slide 123

Slide 123 text

How does GC impact? require 'benchmark/ips' # GC.disable # Uncomment to measure GC Benchmark.ips do |x| x.report("something") do call_some_method end end

Slide 124

Slide 124 text

Startup Time 12% 13% 34% 41% Compilation Execution Searching GC These Are Not Actual Times

Slide 125

Slide 125 text

https://github.com/byroot/ bootscale This link brought to you by GitHub dot com Advertisement:

Slide 126

Slide 126 text

Startup Time 13% 39% 47% Compilation Execution GC These Are Not Actual Times

Slide 127

Slide 127 text

Startup Time 46% 54% Compilation Execution These Are Not Actual Times

Slide 128

Slide 128 text

Lets tackle compilation!

Slide 129

Slide 129 text

Go to @_ko1’s talk

Slide 130

Slide 130 text

that was yesterday…

Slide 131

Slide 131 text

Program Flow Source Code Byte Code Execution Cache this!

Slide 132

Slide 132 text

Program Flow Source Code Byte Code Execution Read Byte Code from File Byte Code Execution

Slide 133

Slide 133 text

Compilation Script input_file = ARGV[0] output_file = input_file + "c" insns = RubyVM::InstructionSequence.compile_file input_file File.binwrite output_file, insns.to_binary New in Ruby 2.3!

Slide 134

Slide 134 text

Compilation Example $ cat hello.rb class Hello def hello! puts "hello" end end $ ruby compile.rb hello.rb $ cat hello.rbc YARB? LX?x86_64-darwin15*0*3 +3DD*???????**0*3 $t|????????||T? Ehello!EhelloEHelloEputsEcore#define_methodx????8Qj?

Slide 135

Slide 135 text

1st half is done

Slide 136

Slide 136 text

Load & Execute Byte Code compiled_file = ARGV[0] binary_data = File.binread compiled_file insns = RubyVM::InstructionSequence.load_from_binary binary_data insns.eval Hello.new.hello! New in Ruby 2.3!

Slide 137

Slide 137 text

Run it $ ruby load_compiled_file.rb hello.rbc hello

Slide 138

Slide 138 text

2nd half is done

Slide 139

Slide 139 text

100% done, but Rails isn’t faster

Slide 140

Slide 140 text

I always give 110%

Slide 141

Slide 141 text

Integrating with `require`

Slide 142

Slide 142 text

Require Process # a.rb require 'b' # b.rb require 'c' # c.rb require 'b'

Slide 143

Slide 143 text

Dependencies a.rb b.rb c.rb

Slide 144

Slide 144 text

Require Process Start to require 'b' Acquire lock for "b" Start to require 'c' Acquire lock for "c" Try to require 'b' Already locked for "b" Finish require 'c' Finish require 'b' Release lock for "c" Release lock for "b"

Slide 145

Slide 145 text

There are many rules, and I don’t want to figure them out.

Slide 146

Slide 146 text

Load File Hook set_load_required_file_func ->(full_file) { if can_handle?(full_file) # do something true else # do something else false end } require 'foo' I want foo.rb! /path/to/foo.rb

Slide 147

Slide 147 text

https://github.com/tenderlove/ ruby/tree/binload ADVERTISING!!

Slide 148

Slide 148 text

Load Compiled Code if ENV['COMP'] set_load_required_file_func ->(full_path) { fname = full_path + "o" if File.exist? fname insns = RubyVM::InstructionSequence.load_from_binary File.binread fname insns.eval true else insns = RubyVM::InstructionSequence.compile_file full_path File.binwrite fname, insns.to_binary false end } end https://gist.github.com/tenderlove/f6f4189db2eb748802b21a8b4fd52c99

Slide 149

Slide 149 text

Compiled vs Non-Compiled [aaron@TC omglolwut (master)]$ time RUBYOPT='-I. -rx' bin/rails db:migrate real 0m1.804s user 0m1.487s sys 0m0.414s [aaron@TC omglolwut (master)]$ time COMP=1 RUBYOPT='-I. -rx' bin/rails db:migrate real 0m1.273s user 0m1.002s sys 0m0.374s Before (not compiled) After (compiled)

Slide 150

Slide 150 text

~30% faster Try mechanical keyboards today! Advertisement:

Slide 151

Slide 151 text

The more code, the bigger the impact.

Slide 152

Slide 152 text

Future Work Upstream new callback Compile code on `gem install` Cache invalidation If you like "cache invalidation", try "naming things"! Advertisement:

Slide 153

Slide 153 text

Runtime Performance

Slide 154

Slide 154 text

Polymorphic Inline Caching

Slide 155

Slide 155 text

Inline Caching class Hello def bar; end end def foo(object) object.bar end foo Hello.new foo Hello.new `object` is Hello, where is foo? `object` is Hello, I know where foo is. HIT! Cache Contents Key Value [Hello, foo] method source

Slide 156

Slide 156 text

Inline Caching class Hello def bar; end end class World def bar; end end def foo(object) object.bar end foo Hello.new foo World.new `object` is Hello, where is foo? MISS `object` is World, where is foo? MISS Cache Contents Key Value [Hello, foo] method source

Slide 157

Slide 157 text

Cache size: 1

Slide 158

Slide 158 text

Monomorphic Inline Cache

Slide 159

Slide 159 text

Cache size: 2 class Hello def bar; end end class World def bar; end end def foo(object) object.bar end foo Hello.new foo World.new foo Hello.new foo World.new `object` is Hello, where is foo? MISS `object` is World, where is foo? MISS `object` is Hello, I know foo. HIT `object` is World, I know foo. HIT Cache Contents Key Value [Hello, foo] method source [World, foo] method source

Slide 160

Slide 160 text

Cache size 2 (or more)

Slide 161

Slide 161 text

Polymorphic Inline Cachine

Slide 162

Slide 162 text

Pays off when many call sites "see" many types.

Slide 163

Slide 163 text

Implemented here: https://github.com/tenderlove/ruby/tree/PIC_expand

Slide 164

Slide 164 text

TL;DR: Didn’t help

Slide 165

Slide 165 text

~3% of calls saw 2 types Test App: https://github.com/manageiq/manageiq Current Company Previous Company

Slide 166

Slide 166 text

Tradeoff: Complexity / Memory For Speed

Slide 167

Slide 167 text

Call site with 1600 types

Slide 168

Slide 168 text

Class Creation Code class Hello end def foo(object) object.bar end 2.times { hello = Hello.new hello.instance_eval do end } Creates a new subclass of Hello Always sees an anonymous class

Slide 169

Slide 169 text

What class is this? class Hello end var = Hello.new Ancestors BasicObject Kernel Object Hello #

Slide 170

Slide 170 text

Singleton Uses • instance_eval • singleton_class • def my_obj.some_method; end

Slide 171

Slide 171 text

Given "I’m a Rails Dev" When "Presented with this info" Then "Why should I care?" Brought to you by rspec-given. It’s a Given! Advertisement:

Slide 172

Slide 172 text

Some libraries do this

Slide 173

Slide 173 text

Don’t write code like that

Slide 174

Slide 174 text

If you think you have to

Slide 175

Slide 175 text

Just don’t. This slide brought to you by singleton classes Advertisement:

Slide 176

Slide 176 text

If you really really really must Brought to you by eigenclasses Advertisement:

Slide 177

Slide 177 text

We can speed it up.

Slide 178

Slide 178 text

Singleton classes with no new methods are equal to the superclass Your ad here! Contact @tenderlove for details Advertisement:

Slide 179

Slide 179 text

Patch to Copy $ git diff trunk class.c diff --git a/class.c b/class.c index 0261838..65428be 100644 --- a/class.c +++ b/class.c @@ -1591,7 +1591,9 @@ singleton_class_of(VALUE obj) klass = RBASIC(obj)->klass; if (!(FL_TEST(klass, FL_SINGLETON) && rb_ivar_get(klass, id_attached) == obj)) { + rb_serial_t serial = RCLASS_SERIAL(klass); klass = rb_make_metaclass(obj, klass); + RCLASS_SERIAL(klass) = serial; } if (OBJ_TAINTED(obj)) { https://github.com/tenderlove/ruby/tree/singleton-serial

Slide 180

Slide 180 text

Benchmark class C1 def m; 1; end end o1 = C1.new o2 = C1.new o2.singleton_class i = 0 while i<6_000_000 # benchmark loop 2 o = (i % 2 == 0) ? o1 : o2 o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m i += 1 end

Slide 181

Slide 181 text

Run it! [aaron@TC ruby (trunk)]$ time ./ruby benchmark/ bm_vm2_poly_singleton.rb real 0m2.510s user 0m2.453s sys 0m0.024s [aaron@TC ruby (singleton-serial)]$ time ./ruby benchmark/ bm_vm2_poly_singleton.rb real 0m1.380s user 0m1.319s sys 0m0.020s

Slide 182

Slide 182 text

45% faster!

Slide 183

Slide 183 text

Trade off: Complexity for Speed

Slide 184

Slide 184 text

Memory Efficiency

Slide 185

Slide 185 text

Copy on Write (a.k.a. CoW) Milk! It’s what’s for dinner Advertisement:

Slide 186

Slide 186 text

Heap Layout Optimizations

Slide 187

Slide 187 text

Copy on Write Parent Process Child Process Child Process Memory

Slide 188

Slide 188 text

Copy on Write Parent Process Child Process Child Process Memory Memory

Slide 189

Slide 189 text

"Page Fault"

Slide 190

Slide 190 text

OS copies some of the memory

Slide 191

Slide 191 text

Ruby Memory Layout Pages Object Object Object Object Object Object Object Object Object Object Object Object

Slide 192

Slide 192 text

GC Happens Pages Object Object Object Object Object Object Object Object Object Object FREE! FREE! FREE! FREE! Object Object

Slide 193

Slide 193 text

Objects Don’t Move

Slide 194

Slide 194 text

Swiss Cheese Memory Pages Object FREE! FREE! Object FREE! FREE! Object Object Object Object Object Object

Slide 195

Slide 195 text

CoW wastefulness Pages Object FREE! FREE! Object FREE! FREE! Object Object Object Object Object Object Object Parent Child Copied to Child

Slide 196

Slide 196 text

OS Page Size 4k Ruby Page Size 16k Ruby Object Size 40 bytes

Slide 197

Slide 197 text

1 Ruby Page: ~400 Objects

Slide 198

Slide 198 text

1 Ruby Page: 4 OS Pages

Slide 199

Slide 199 text

1 OS Page: ~100 Ruby Objects

Slide 200

Slide 200 text

We’re probably copying too many objects. Try JRuby: it’s Ruby with a J Advertisement:

Slide 201

Slide 201 text

This only impacts Ruby code that forks.

Slide 202

Slide 202 text

Unicorn Ugh. This is the web server we use.

Slide 203

Slide 203 text

Sideways Ruby Page

Slide 204

Slide 204 text

Sideways Ruby Page Imaginary Ruby Page (Slab)

Slide 205

Slide 205 text

Pages dedicated to "probably old" objects

Slide 206

Slide 206 text

What are "probably old" objects?

Slide 207

Slide 207 text

Probably old class Foo end module Bar end BAZ = "OMGOMG!!"

Slide 208

Slide 208 text

Tradeoffs?

Slide 209

Slide 209 text

Complexity for memory?

Slide 210

Slide 210 text

How complex?

Slide 211

Slide 211 text

How much memory?

Slide 212

Slide 212 text

Tools for introspection

Slide 213

Slide 213 text

github.com/tenderlove/heapfrag Sponsored link:

Slide 214

Slide 214 text

No content

Slide 215

Slide 215 text

Wrap it up!!

Slide 216

Slide 216 text

5 lessons

Slide 217

Slide 217 text

What do I value? What should I measure How can I measure it Does it provide shareholder value?

Slide 218

Slide 218 text

5

Slide 219

Slide 219 text

1. What do I value?

Slide 220

Slide 220 text

2. What should I measure?

Slide 221

Slide 221 text

3. How can I measure it?

Slide 222

Slide 222 text

4. Does it provide shareholder value? ActionCable: it’s a thing!! Advertisement:

Slide 223

Slide 223 text

Make Rails Great Again!

Slide 224

Slide 224 text

No content