-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
@tenderworks had the idea that maybe lazy initialization of an ivar should be a single VM instruction. For example, right now,
class C
attr_accessor :a
def a
@a ||= 5
end
endcompiles into
== disasm: #<ISeq:a@tmp/lazyinit.rb:3 (3,2)-(5,5)>
0000 getinstancevariable :@a, <is:0> ( 4)[LiCa]
0003 dup
0004 branchif 13
0006 pop
0007 putobject 5
0009 dup
0010 setinstancevariable :@a, <is:1>
0013 leave
a) that's a lot of code and b) would it be possible to get better IC hit behavior? Right now this pattern has IC misses the first two calls (first empty, second is filled but wrong)
Metadata
Metadata
Assignees
Labels
No labels