Repository navigation
speed up dict cast key width - #11502
Merged
Merged
Conversation
Rich-T-kid
commented
Oct 12, 2026
Rich-T-kid
left a comment
Contributor
Author
There was a problem hiding this comment.
I think this is self evident enough to not warrant benchmarks
Rich-T-kid
marked this pull request as ready for review
October 12, 2026 00:37
Rich-T-kid
force-pushed
the
rich-T-kid/dict-cast-key-width
branch
from
October 16, 2026 16:00
5f69b73 to
81ba7eb
Compare
Jefffrey
approved these changes
Oct 17, 2026
Rich-T-kid
force-pushed
the
rich-T-kid/dict-cast-key-width
branch
from
October 17, 2026 19:50
81ba7eb to
f94afdf
Compare
Rich-T-kid
force-pushed
the
rich-T-kid/dict-cast-key-width
branch
from
October 17, 2026 20:06
f94afdf to
76b8c9c
Compare
Contributor
|
thanks @Rich-T-kid |
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.
Which issue does this PR close?
Rationale for this change
Dictionary(K1, V) → Dictionary(K2, V)casts (changing only the key width) currently take the general path indictionary_to_dictionary_cast, which does three things that are unnecessary when the value type is unchanged:cast_with_optionson the values array — dispatch overhead even for identity casts, real work for near-identity casts.ArrayDatagraph viainto_builder().child_data(...).build_unchecked().DictionaryArray::<K2>::from(data), which runs anO(N_rows)bounds-check pass over every key.If the source dict was valid and the key cast didn't overflow, the result is valid by construction
What changes are included in this PR?
A fast path in
dictionary_to_dictionary_cast: when the source value type equals the target value type (and the source isn't a nested dict), delegate tocast_keys_only, which casts the keys array and reuses the valuesArcviaDictionaryArray::new_unchecked. Narrowing overflow remains a hard error regardless ofcast_options.safe, same contract as the general path.Are these changes tested?
Are there any significant user-facing changes?
no