Skip to content

Refactor KeyRegularizer to reduce allocations#1120

Merged
petergoldstein merged 1 commit into
petergoldstein:mainfrom
byroot:opt-key-regularizer
Jun 21, 2026
Merged

Refactor KeyRegularizer to reduce allocations#1120
petergoldstein merged 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 2 times, most recently from 8221b99 to 8f2bf0d Compare June 3, 2026 14:43
@petergoldstein

Copy link
Copy Markdown
Owner

@byroot Can you please rebase this and resolve the conflicts? Thanks.

@byroot byroot force-pushed the opt-key-regularizer branch from 8f2bf0d to eb086a6 Compare June 21, 2026 21:10
@byroot

byroot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

Rebased.

@byroot

byroot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

Hum, might need some more changes. Looking.

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 eb086a6 to d18e942 Compare June 21, 2026 21:14
@petergoldstein petergoldstein merged commit e127c90 into petergoldstein:main Jun 21, 2026
10 checks passed
@petergoldstein

Copy link
Copy Markdown
Owner

Thanks @byroot

@byroot byroot deleted the opt-key-regularizer branch June 21, 2026 21:35
petergoldstein added a commit that referenced this pull request Jun 21, 2026
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.

2 participants