Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't call malloc with 0 #8442

Merged
merged 1 commit into from
Sep 14, 2023
Merged

Don't call malloc with 0 #8442

merged 1 commit into from
Sep 14, 2023

Conversation

tenderlove
Copy link
Member

It seems not-uncommon for methods to have no IV, ISE, or ICVARC caches. Calling malloc with 0 will actually allocate something, so if there aren't any caches (ISEQ_IS_SIZE(body) == 0), then we can avoid allocating memory by not calling malloc. If there are no caches, then theoretically nobody should be reading from the buffer anyway.

This saves about 1MB on Lobsters benchmark.

Launch_ruby_2023-09-14_12 45 26_ABEF074A 2023-09-14 12-52-04

It seems not-uncommon for methods to have no IV, ISE, or ICVARC caches.
Calling malloc with 0 will actually allocate something, so if there
aren't any caches (`ISEQ_IS_SIZE(body) == 0`), then we can avoid
allocating memory by not calling malloc.  If there are no caches, then
theoretically nobody should be reading from the buffer anyway.

This saves about 1MB on Lobsters benchmark.
@tenderlove tenderlove merged commit f08cac0 into ruby:master Sep 14, 2023
91 of 92 checks passed
@tenderlove tenderlove deleted the no-empty-alloc branch September 14, 2023 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant