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

ruby: use rb_interned_str when available #12

Merged
merged 1 commit into from
Jan 18, 2022

Conversation

casperisfine
Copy link
Contributor

This API was introduced with Ruby 3.0
Ref: https://bugs.ruby-lang.org/issues/16029

It allows to re-used an existing interned string when possible. Since column names are very often present in the codebase, the hitrate is generally good.

One issue here however is that column names are created in ASCII because the Ruby client doesn't know what the connection encoding is.

So it won't be able to re-use literal strings from the codebase, however it will re-use the strings backing symbols (they are ASCII).

But even on misses, since Hash#[]= will always try to dedup the string by always getting an interned string, we save that extra lookup later when using Result#each_hash.

Similar change in MySQL2: brianmario/mysql2#1181

This API was introduced with Ruby 3.0
Ref: https://bugs.ruby-lang.org/issues/16029

It allows to re-used an existing interned string when possible.
Since column names are very often present in the codebase, the hitrate
is generally good.

One issue here however is that column names are created in ASCII because
the Ruby client doesn't know what the connection encoding is.

So it won't be able to re-use literal strings from the codebase, however
it will re-use the strings backing symbols (they are ASCII).

But even on misses, since `Hash#[]=` will always try to dedup the string
by always getting an interned string, we save that extra lookup later when using
`Result#each_hash`.
@matthewd matthewd merged commit 5b5f93e into trilogy-libraries:main Jan 18, 2022
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.

3 participants