Repository navigation
Consult udunits once per distinct symbol in as_units() - #441
Merged
Enchufa2 merged 2 commits intoSep 22, 2026
Merged
Conversation
The tokenizer represents a power as one copy of the symbol per unit of
exponent, and as_units.character() then called ud_is_parseable() and
ud_get_symbol() once per copy, so "m255 s-255" cost 510 udunits round
trips for two distinct symbols. Look each distinct symbol up once and
map the results back with match(). As a side effect an unrecognized
symbol is now reported once ("'x' is not recognized") instead of once
per copy.
Median of 20 runs of as_units() with bench::mark, before and after:
case string before after
typical kg m-2 s-1 0.26 ms 0.25 ms
moderate kg2 m4 s-6 A-2 0.54 ms 0.29 ms
max_exponent m255 s-255 14.15 ms 0.43 ms
unknown x-2000 1160.25 ms 2.14 ms
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Follow-up to #439, split out as requested there.
Fixes #440
The tokenizer represents a power as one copy of the symbol per unit of exponent, and
as_units.character()then calledud_is_parseable()andud_get_symbol()once per copy, som255 s-255cost 510 udunits round trips for two distinct symbols. This looks each distinct symbol up once and maps the results back withmatch(). As a side effect an unrecognized symbol is reported once ('x' is not recognized) instead of once per copy, which the new test pins.Median of 20 runs of
as_units()withbench::mark, before and after:kg m-2 s-1kg2 m4 s-6 A-2m255 s-255x-2000🤖 Generated with Claude Code