mirror of
https://github.com/ruby/ruby.git
synced 2026-11-08 01:20:26 +08:00
Profiling of `ruby --disable-all -e 1` shows between 5 and 10% of the time is spent in `_platform_memset`, called from `rb_gccct_clear_table()`, itself called from `clear_method_cache_by_id_in_class()`. Which makes sense, during boot we define numerous methods, and after each we have to invalidate the `gccct`, which is done by zeroing 1023 pointers, so roughtly 8kiB of memory. By keeping track of whether the table was used since the last clear, we can save a lot of useless memory writes. This may also be beneficial when loading user defined code, as it's unlikely the `gccct` would be dirtied between two `def`. NB: profiling such a short lived process gives a lot of variance, but with a very high sampling rate and multiple attempts, `clear_method_cache_by_id_in_class` is always in the top 2 hotspots. (cherry picked from commit 14eb0831527b8e1c5bbfef21ecaed14b21103315)