1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/internal
Kevin Newton 629908586b Finer-grained inline constant cache invalidation
Current behavior - caches depend on a global counter. All constant mutations cause caches to be invalidated.

```ruby
class A
  B = 1
end

def foo
  A::B # inline cache depends on global counter
end

foo # populate inline cache
foo # hit inline cache

C = 1 # global counter increments, all caches are invalidated

foo # misses inline cache due to `C = 1`
```

Proposed behavior - caches depend on name components. Only constant mutations with corresponding names will invalidate the cache.

```ruby
class A
  B = 1
end

def foo
  A::B # inline cache depends constants named "A" and "B"
end

foo # populate inline cache
foo # hit inline cache

C = 1 # caches that depend on the name "C" are invalidated

foo # hits inline cache because IC only depends on "A" and "B"
```

Examples of breaking the new cache:

```ruby
module C
  # Breaks `foo` cache because "A" constant is set and the cache in foo depends
  # on "A" and "B"
  class A; end
end

B = 1
```

We expect the new cache scheme to be invalidated less often because names aren't frequently reused. With the cache being invalidated less, we can rely on its stability more to keep our constant references fast and reduce the need to throw away generated code in YJIT.
2022-03-24 09:14:38 -07:00
..
array.h
bignum.h
bits.h
class.h Dedup superclass array in leaf sibling classes 2022-03-03 11:23:27 -08:00
cmdlineopt.h * expand tabs. [ci skip] 2022-01-15 20:10:30 +09:00
compar.h
compile.h
compilers.h
complex.h
cont.h
dir.h
enc.h
encoding.h
enum.h
enumerator.h
error.h
eval.h
file.h
fixnum.h
gc.h Change darray size to size_t and add functions that use GC malloc 2022-02-16 09:50:29 -05:00
hash.h
imemo.h
inits.h
io.h
load.h
loadpath.h
math.h
missing.h
numeric.h
object.h
parse.h
proc.h
process.h
random.h
range.h
rational.h
re.h
sanitizers.h
serial.h
signal.h
static_assert.h
string.h
struct.h
symbol.h
thread.h
time.h
transcode.h
util.h
variable.h
vm.h Finer-grained inline constant cache invalidation 2022-03-24 09:14:38 -07:00
warnings.h