RubyConf 2017 Day Three

Ruby Conf 2017 Day Three

You’re insufficiently persuasive by Sandi Metz


Top external problems

  1. Time pressure
  2. Bad code quality and coding practice
  3. Unexplained broken code
  4. Bad decision making
  5. Imposing limitation on development


Influence: The Psychology of Persuasion by Robert B. Cialdini

  1. Reciprocity
    • Evolutionary tendency to form groups, and the expectation that when you give up something you will receive something bigger in return
    • Hare Krishnas heavily relied on this psychological concept, they’d force push flowers on people for money, and people felt they had to reciprocate even though they had no use for these flowers
  2. Consistency
    • you promised, and it’s hard to break a promise. That’s how the retailers are able to increase the price of toys around holidays, because a child’s expectations for a toy makes it difficult for a parent to renege on a promise, regardless of the price
  3. Social Proof
    • we are more likely to follow what other people do
    • being ostricized for doing something that isn’t the norm is a psychological barrier to overcome
  4. Authority

  5. Liking
    • tend to like people who are similar to us
    • tend to like people who we have interacted well with in the past
    • trust
    • you understand that you’re bound implicitly by obligiations that you don’t want to fulfill
  6. Scarcity
    • the value of things go up when there are fewer things
    • that’s why Amazon tells you only 7 items of something are left
    • the more value you place on something the more unwiling people are to let it go, for example a parking space

How to Win Friends & Influence People by Dale Carnegie

How do you know you’re right?

Drive by Daniel H. Pink

as soon as pay becomes sufficient, other motivations become relevant

  1. autonomy
  2. drive to mastery
  3. purpose


Project Aristole by Google

Psycholoical safety

The fundamental thing that differentiate high performing team to dysfunctional ones are how the members of the team speak and treat each other. Higher performing teams inculcated a group culture where everyone feels comfortable to speak.

A culture of accountability and clear goals are also important but psychological safety is the most important trait

Other suggestions

Building a Compacting GC for MRI by Aaron Patterson

Be here, write ruby, tell your friends

Mark / Compact GC

Low level talk, for new people

Algorithms and Implemntation details

CoW (Copy on Write)

Don’t copy something until we write to it

String example

p = 'foo'
p.ObjectSpace.memsize_of(str) => 9021
p2.ObjectSpace.memsize_of(str) => 40
p2 = 'bar'
p2.ObjectSpace.memsize_of(str) => 9021 # memory isn't allocated until write happens

Same for array and hashes but larger than strings.

The principle is that there are no obersvable differences when we do copy on write and it saves a lot of space on the heap.

Another example is the ruby fork

Parent process

string = 'x' * 000

Child process copies on write

child_pid = fork do
gets s

CoW Page Fault

when the child process doesn’t copy correctly

Unicorn study

Unicorn is a forking webserver

Unicorn Parent
|                 \       \
Unicorn Child1, Child2, Child3

Problem is if child process loads a copy of rails we wind up with 3 copies of rails

If Unicorn parent loads the parent rails and then have the child process make a copy of the parent process, then we only make one copy of the parent. This is how unicorn works today. What I am doing is proving to myself that it’s possible to use CoW to perform some optimizations before unicorn parent forks.

What causes CoW Page fault? Mutating share memory

1. garbage collector

Mark phase, OS copies one page

GC Mark vs. Bitmark collecor, Bitmark is smaller


Generation are bounded, objects created before ‘fork’ will get old GC are few times before we fork

2. Object allocation

The other place where GC will write to memory is object allocation

Compaction algorithm

Tools to examine heap

We can examine the heap by dumping out the object space and map the memory addresses to the

require 'objspace'

Conclusion: There are a lot of objects that we cannot move, compaction savings are unknown.

LLVM-based JIT compiler for MRI by Takashi Kokubun

Ruby 2.5

What’s JIT compiler

How the current MRI works

ruby code

def urby
3 * 3
abstract syntax tree
bytecode VM

There are several varieties of JIT compilers and the subject matter was too difficult for me to understand, but it seems that he went through two versions of them in 6 months, and eventually forked from one of the JIT compilers and optimized it.

Fireside chat with Matz