You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jhorstmann (via GitHub)" <gi...@apache.org> on 2023/03/08 18:32:16 UTC

[GitHub] [arrow-rs] jhorstmann commented on a diff in pull request #3801: Faster timestamp parsing (~70-90% faster)

jhorstmann commented on code in PR #3801:
URL: https://github.com/apache/arrow-rs/pull/3801#discussion_r1129875692


##########
arrow-cast/src/parse.rs:
##########
@@ -15,11 +15,117 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use arrow_array::timezone::Tz;
 use arrow_array::types::*;
 use arrow_array::ArrowPrimitiveType;
 use arrow_schema::ArrowError;
 use chrono::prelude::*;
 
+/// Helper for parsing timestamps
+struct TimestampParser {
+    digits: [u8; 32],
+    mask: u32,
+}
+
+impl TimestampParser {
+    fn new(bytes: &[u8]) -> Self {
+        let mut digits = [0; 32];
+        let mut mask = 0;
+
+        for (idx, (o, i)) in digits.iter_mut().zip(bytes).enumerate() {

Review Comment:
   fun fact, this would a a handful of instructions without any loops with avx512. unfortunately still requires nightly, and we should probably find a general answer to target-specific optimizations first, instead of sprinkling intrinsics all over the place. In case you want to benchmark it, the code would look like
   
   ```rust
               use std::arch::x86_64::*;
               unsafe {
                   let load_mask = u32::MAX >> 32_usize.saturating_sub(bytes.len());
                   let v = _mm256_maskz_loadu_epi8(load_mask, bytes.as_ptr().cast());
                   let d = _mm256_sub_epi8(v, _mm256_set1_epi8(b'0' as _));
                   _mm256_storeu_si256(digits.as_mut_ptr().cast(), d);
                   mask = _mm256_cmplt_epu8_mask(d, _mm256_set1_epi8(10));
               }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org