Repository navigation
Avoid creating String for every key - #71
Merged
Merged
Conversation
format_key called Symbol#to_s, which returns a new String on every call, so each key emitted allocated one. Symbol#name returns the frozen String Ruby already keeps for the Symbol instead, so repeated keys allocate nothing. String keys still go through to_s, which returns them as-is. Symbol#name has been available since Ruby 3.0, and the gemspec requires 3.3 or later. On alba's collection benchmark this cuts allocations per render from 7,923 to 3,523 objects (-56%).
jho406
force-pushed
the
perf-improve-obj-allocations
branch
from
October 17, 2026 21:12
d060d09 to
2862404
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
format_keycalledto_s, which returns a new String each time, so every key emitted allocated one. Symbol#name returns the internal allocated frozen String. Its been available since Ruby 3.0, and since we've pinned it to 3.3 +, we're can treat this as a patch.Improvements are great. I'm looking at a 50% decrease in the number of allocation using alba benchmarks.