Skip to content

Refactor KeyRegularizer to reduce allocations#1120

Open
byroot wants to merge 1 commit into
petergoldstein:mainfrom
byroot:opt-key-regularizer
Open

Refactor KeyRegularizer to reduce allocations#1120
byroot wants to merge 1 commit into
petergoldstein:mainfrom
byroot:opt-key-regularizer

Conversation

@byroot

@byroot byroot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Interfaces that return multi values aren't great in hotspot as they require to allocate a very short lived array and the Ruby VM isn't yet sophisticated enough to elude it.

But since in the happy path we only need to check if the key need to be encoded, we can decompose that single method into two calls, and save more performance on the happy path (one allocation) than we lose on the slow path (one method call).

Also refactor multi_get / multi_set / multi_delete to be generated by RequestFormatter so that they can use its internal helpers to encode keys.

@byroot byroot force-pushed the opt-key-regularizer branch from 5e551e7 to 8221b99 Compare June 3, 2026 14:37
Interfaces that return multi values aren't great in hotspot
as they require to allocate a very short lived array and the
Ruby VM isn't yet sophisticated enough to elude it.

But since in the happy path we only need to check if the key
need to be encoded, we can decompose that single method into
two calls, and save more performance on the happy path (one allocation)
than we lose on the slow path (one method call).

Also refactor `multi_get / multi_set / multi_delete` to be generated
by `RequestFormatter` so that they can use its internal helpers to
encode keys.
@byroot byroot force-pushed the opt-key-regularizer branch from 8221b99 to 8f2bf0d Compare June 3, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant