support suffix white space in arrow-cast parse#10396
Conversation
|
run benchmark cast_kernels |
This comment has been minimized.
This comment has been minimized.
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤔 it seems to be slower |
|
run benchmark cast_kernels |
1 similar comment
|
run benchmark cast_kernels |
This comment has been minimized.
This comment has been minimized.
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
This comment has been minimized.
This comment has been minimized.
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
yea its consistently slower 🤔 for the case where there is no white space we do three comparissions (1 for the prefix, 1 for the suffix, 1 for the suffix again) |
|
run benchmark cast_kernels |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
I don't think theres a way to avoid the extra checks white-spase stripping requires. Even when there is no extra space, this pr adds a prefix check, a suffix check and another suffix check just to do nothing else. we could add a conditional compilation attribute but that may be overkill. |
|
im just curious how the previous PR seemed to suggest 0 regressions, meanwhile adding one more causes a noticeable bump though we are at the single digit microsecond scale |
@Jefffrey i am as-well. I think it has to do with the number of checks. In the previous PR, we only added three comparisons:
this PR has those exact same checks but twice and we also have two exta comparissions for the so about 8 extra comparisons. we could add something like |
|
mabey? #[inline]
fn trim_pre_and_post_whitespace(string: &str) -> &str {
let bytes = string.as_bytes();
let prefix = bytes.first().is_some_and(|b| !b.is_ascii_digit());
let suffix = bytes.last().is_some_and(|b| !b.is_ascii_digit());
match (prefix, suffix) {
(false, false) => string,
(true, false) => {
cold_path();
string.trim_ascii_start()
}
(false, true) => {
cold_path();
string.trim_ascii_end()
}
(true, true) => {
cold_path();
string.trim_ascii()
}
}
}this looks a bit clunky to me |
|
something silly we could do is always assume the best case and have the worst case (need to trim) as a fallback impl Parser for Float32Type {
fn parse(string: &str) -> Option<f32> {
if let Ok(n) = lexical_core::parse(string.as_bytes()) {
Some(n)
} else {
let string = string.trim_ascii();
lexical_core::parse(string.as_bytes()).ok()
}
}
}since the benchmarks are testing the casting of arrays themselves (and not just a microbenchmark of this parse function) i think it would be good to aim for a way to avoid regressions if possible 🤔 that being said, its worth noting our benchmark only checks f32, and tests arrays of fixed 512 length, so its not like the suite is comprehensive to the changes being made here |
makes sense to me. Could we run the benchmarks again |
|
run benchmark cast_kernels |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
run benchmark cast_kernels |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
nice |
| fn parse(mut string: &str) -> Option<Self::Native> { | ||
| if !string.as_bytes().last().is_some_and(|x| x.is_ascii_digit()) { | ||
| return None; | ||
| fn parse(string: &str) -> Option<Self::Native> { |
There was a problem hiding this comment.
perhaps we can add one benchmark for i32 just so we have a reference
# Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. --> - none. # Rationale for this change see #10396 (comment) <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> # What changes are included in this PR? adds benchmarks for str -> i32 <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> # Are these changes tested? n/a <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? If this PR claims a performance improvement, please include evidence such as benchmark results. --> # Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. If there are any breaking changes to public APIs, please call them out. --> no
|
run benchmark cast_kernels |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: CPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
Merge up to get fix for MIRI |
alamb
left a comment
There was a problem hiding this comment.
Thank you @Rich-T-kid and @Jefffrey
| if let Ok(raw_float) = lexical_core::parse(string.as_bytes()) { | ||
| return Some(f16::from_f32(raw_float)); | ||
| } | ||
| let string = trim_pre_and_post_whitespace(string); |
There was a problem hiding this comment.
this is a good strategy -- try the common/ fast path first and then fallback to checking whitespace afterwards
|
🚀 |
Which issue does this PR close?
Rationale for this change
What changes are included in this PR?
this PR adds support for suffix white space when calling parse
Are these changes tested?
yes
Are there any user-facing changes?
yes, users will be able to parse strings that have white space prefixed/suffixed onto numbers/floats.