blob: 90f6b07f05de41fbb00972c0c83b8c072587b581 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
prelude: |
IVARS = 60
class Record
def initialize(offset = false)
@offset = 1 if offset
@first = 0
IVARS.times do |i|
instance_variable_set("@ivar_#{i}", i)
end
end
def first
@first
end
def lazy_set
@lazy_set ||= 123
end
def undef
@undef
end
end
Record.new # Need one alloc to right size
BASE = Record.new
LAZY = Record.new
LAZY.lazy_set
class Miss < Record
@first = 0
IVARS.times do |i|
instance_variable_set("@i_#{i}", i)
end
end
Miss.new # Need one alloc to right size
MISS = Miss.new
DIVERGENT = Record.new(true)
benchmark:
vm_ivar_stable_shape: |
BASE.first
BASE.first
BASE.first
BASE.first
BASE.first
BASE.first
vm_ivar_memoize_unstable_shape: |
BASE.first
LAZY.first
BASE.first
LAZY.first
BASE.first
LAZY.first
vm_ivar_memoize_unstable_shape_miss: |
BASE.first
MISS.first
BASE.first
MISS.first
BASE.first
MISS.first
vm_ivar_unstable_undef: |
BASE.undef
LAZY.undef
BASE.undef
LAZY.undef
BASE.undef
LAZY.undef
vm_ivar_divergent_shape: |
BASE.first
DIVERGENT.first
BASE.first
DIVERGENT.first
BASE.first
DIVERGENT.first
vm_ivar_divergent_shape_imbalanced: |
BASE.first
DIVERGENT.first
DIVERGENT.first
DIVERGENT.first
DIVERGENT.first
DIVERGENT.first
|