Hash#merge
• It has used rb_obj_dup() and it’s calling
rb_funcall()
Slide 26
Slide 26 text
rb_obj_dup()
• It calls Object#initialize_dup via rb_funcall()
Slide 27
Slide 27 text
rb_obj_dup()
• It calls Object#initialize_dup via rb_funcall()
• Replace rb_obj_dup() to something like rb_ary_dup()
to remove redundant Object#initialize_dup
Slide 28
Slide 28 text
Patch for Hash#merge
Slide 29
Slide 29 text
Patch for Hash#merge
• Replaced rb_obj_dup() to remove rb_funcall()
Slide 30
Slide 30 text
Hash#merge performance
Y
Y
Y
Y
Y
Y
3VCZ 3VCZEFW
Y
Y
hash1 = { "a" => 100, "b" => 200 }
hash2 = { "b" => 254, "c" => 300 }
hash1.merge(hash2)
Slide 31
Slide 31 text
Patch for Time (1)
Slide 32
Slide 32 text
Patch for Time (2)
Slide 33
Slide 33 text
Patch for Time (3)
Slide 34
Slide 34 text
Time methods
• Time methods called Ruby methods via
rb_funcall()
Slide 35
Slide 35 text
Time methods
• Time methods called Ruby methods via
rb_funcall()
• Added some internal APIs to call method directly
Slide 36
Slide 36 text
Time#- performance
Y
Y
Y
Y
Y
Y
3VCZ 3VCZEFW
Y
Y
Time.now - Time.at(0)
Slide 37
Slide 37 text
Others
Slide 38
Slide 38 text
Result (2.4.1 vs 2.5.0-dev)
"SSBZ
Y
Y
Y
Y
Y
)BTI
Y
Y
Y
Y
Y
4USJOH
Y
Y
Y
Y
Y
5JNF
Y
Y
Y
Y
Y
Ubuntu 17.04
gcc version 7.0.1
ruby 2.5.0dev (2017-08-27 trunk 59665) [x86_64-linux]
Slide 39
Slide 39 text
Top 10
4USJOH PUIFS
4USJOHJOTFSU QPT
PUIFS
"SSBZSBTTPD PCK
5JNFTVCTFD
5JNFUP@J
5JNFUW@TFD
)BTIIBT@WBMVF OPWBMVF
)BTIWBMVF OPWBMVF
5JNFUP@S
"SSBZNBY O
….
….
….
….
Before After
Concatenate heap areas
2 allocations 1 allocation
Slide 51
Slide 51 text
Hash literal performance
Y
Y
Y
Y
Y
Y
Y
Before After
h = {foo: 12, bar: 34, baz: 56}
Caution:
This is just prototype
Slide 52
Slide 52 text
vs. Ruby 2.4.1
After
Ruby 2.4.1 Base : ruby 2.5.0dev (2017-09-10 trunk 59745) [x86_64-linux]
Y
Y
Y
Y
Y
Y
Y
Caution:
This is just prototype
h = {foo: 12, bar: 34, baz: 56}
Slide 53
Slide 53 text
You might learn:
• How to measure
• Some ways to optimize effectively
• A part of current Ruby-dev status