Make rb_check_frozen_inline() static inline again

Since 730e3b2ce0
("Stop exposing `rb_str_chilled_p`"), we noticed a speed loss on a few
benchmarks that are string operations heavy. This is partially due to
routines no longer having the options to inline rb_check_frozen_inline()
in non-LTO builds. Make it an inlining candidate again to recover speed.

Testing this patch on my machine, the fannkuchredux benchmark gets a
1.15 speed-up with YJIT and 1.03 without YJIT.
This commit is contained in:
Alan Wu 2024-07-19 15:53:16 -04:00
Родитель 30f2d69825
Коммит 8cf708d7b4
2 изменённых файлов: 20 добавлений и 8 удалений

Просмотреть файл

@ -4001,13 +4001,7 @@ rb_error_frozen_object(VALUE frozen_obj)
void
rb_check_frozen(VALUE obj)
{
if (RB_UNLIKELY(RB_OBJ_FROZEN(obj))) {
rb_error_frozen_object(obj);
}
if (RB_UNLIKELY(CHILLED_STRING_P(obj))) {
rb_str_modify(obj);
}
rb_check_frozen_inline(obj);
}
void

Просмотреть файл

@ -237,6 +237,8 @@ RBIMPL_ATTR_NORETURN()
*/
void rb_error_arity(int argc, int min, int max);
void rb_str_modify(VALUE str);
RBIMPL_SYMBOL_EXPORT_END()
/**
@ -247,7 +249,23 @@ RBIMPL_SYMBOL_EXPORT_END()
#define rb_check_frozen_internal rb_check_frozen
/** @alias{rb_check_frozen} */
#define rb_check_frozen_inline rb_check_frozen
static inline void
rb_check_frozen_inline(VALUE obj)
{
if (RB_UNLIKELY(RB_OBJ_FROZEN(obj))) {
rb_error_frozen_object(obj);
}
/* ref: internal CHILLED_STRING_P()
This is an implementation detail subject to change. */
if (RB_UNLIKELY(RB_TYPE_P(obj, T_STRING) && FL_TEST_RAW(obj, RUBY_FL_USER3))) {
rb_str_modify(obj);
}
}
/* rb_check_frozen() is available as a symbol, but have
* the inline version take priority for native consumers. */
#define rb_check_frozen rb_check_frozen_inline
/**
* Ensures that the passed integer is in the passed range. When you can use