gc/default/default.c: don't call malloc_usable_size
when hint is present
Depending on the allocator, `malloc_usable_size` may be very cheap or quite expensive. On `macOS` for instance, it's about as expensive as `malloc`. In many case we call `objspace_malloc_size` with as size we initially requested as `hint`. The real usable size may be a few bytes bigger, but since we only use that data to feed GC heuristics, I don't think it's very important to be perfectly accurate. It would make sense to call `malloc_usable_size` after growing a String or Array to use the extra capacity, but here we don't do that, so the call isn't worth its cost.
This commit is contained in:
parent
37361d87a6
commit
22e9fa81ca
Notes:
git
2025-01-05 16:05:13 +00:00
@ -7936,10 +7936,11 @@ static inline size_t
|
||||
objspace_malloc_size(rb_objspace_t *objspace, void *ptr, size_t hint)
|
||||
{
|
||||
#ifdef HAVE_MALLOC_USABLE_SIZE
|
||||
return malloc_usable_size(ptr);
|
||||
#else
|
||||
return hint;
|
||||
if (!hint) {
|
||||
hint = malloc_usable_size(ptr);
|
||||
}
|
||||
#endif
|
||||
return hint;
|
||||
}
|
||||
|
||||
enum memop_type {
|
||||
|
Loading…
x
Reference in New Issue
Block a user