diff options
author | Aaron Patterson <[email protected]> | 2024-04-17 16:30:41 -0700 |
---|---|---|
committer | Aaron Patterson <[email protected]> | 2024-04-18 09:06:33 -0700 |
commit | 147ca9585ede559fd68e162cbbbaba84f009c9a1 (patch) | |
tree | fea2464e46cedbdcd6b6882f908948fd7313647d /vm_callinfo.h | |
parent | 8e08556fa7f2b6e9c43b040f2aea06dccead5d13 (diff) |
Implement equality for CI comparison when CC searching
When we're searching for CCs, compare the argc and flags for CI rather
than comparing pointers. This means we don't need to store a reference
to the CI, and it also naturally "de-duplicates" CC objects.
We can observe the effect with the following code:
```ruby
require "objspace"
hash = {}
p ObjectSpace.memsize_of(Hash)
eval ("a".."zzz").map { |key|
"hash.merge(:#{key} => 1)"
}.join("; ")
p ObjectSpace.memsize_of(Hash)
```
On master:
```
$ ruby -v test.rb
ruby 3.4.0dev (2024-04-15T16:21:41Z master d019b3baec) [arm64-darwin23]
test.rb:3: warning: assigned but unused variable - hash
3424
527736
```
On this branch:
```
$ make runruby
compiling vm.c
linking miniruby
builtin_binary.inc updated
compiling builtin.c
linking static-library libruby.3.4-static.a
ln -sf ../../rbconfig.rb .ext/arm64-darwin23/rbconfig.rb
linking ruby
ld: warning: ignoring duplicate libraries: '-ldl', '-lobjc', '-lpthread'
RUBY_ON_BUG='gdb -x ./.gdbinit -p' ./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems ./test.rb
2240
2368
```
Co-authored-by: John Hawthorn <[email protected]>
Diffstat (limited to 'vm_callinfo.h')
-rw-r--r-- | vm_callinfo.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/vm_callinfo.h b/vm_callinfo.h index 21e0755aa8..1629d9f0a9 100644 --- a/vm_callinfo.h +++ b/vm_callinfo.h @@ -575,7 +575,8 @@ struct rb_class_cc_entries { int len; const struct rb_callable_method_entry_struct *cme; struct rb_class_cc_entries_entry { - const struct rb_callinfo *ci; + unsigned int argc; + unsigned int flag; const struct rb_callcache *cc; } *entries; }; |