You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/12 02:14:02 UTC

[GitHub] [arrow-rs] tfeda opened a new pull request, #2048: Improve `validate_utf8` performance

tfeda opened a new pull request, #2048:
URL: https://github.com/apache/arrow-rs/pull/2048

   # 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. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #1815 .
   
   # Rationale for this change
    
    <!---
    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?
   Added a benchmark for utf8 validation, 
   Followed the suggestions in #1815 with a few notes:
   1. If utf8 validation fails, the new function falls back on executing each index to give a more informed error message
   2. @tustvold `validate_each_offset()` checks if the offsets are sorted, which I don't think we want to lose by switching to `is_char_boundary()`, 
   
   checking the bench I get a ~4x speedup :+1: 
   <!---
   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 there any user-facing changes?
   Nope
   
   <!---
   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 add the `breaking change` label.
   -->
   


-- 
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


[GitHub] [arrow-rs] alamb commented on pull request #2048: Improve `validate_utf8` performance

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2048:
URL: https://github.com/apache/arrow-rs/pull/2048#issuecomment-1183649580

   > Without is_char_boundary this is not correct, it will not detect a multi-byte character split across two consecutive strings.
   
   Sounds like a hole in our tests if all the tests pass but there is a bug 🤔 


-- 
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


[GitHub] [arrow-rs] alamb commented on pull request #2048: Improve `validate_utf8` performance

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2048:
URL: https://github.com/apache/arrow-rs/pull/2048#issuecomment-1195934476

   🎉 Thanks for this contribution @tfeda  and to @tustvold  for helping get it over the line


-- 
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


[GitHub] [arrow-rs] ursabot commented on pull request #2048: Improve `validate_utf8` performance

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #2048:
URL: https://github.com/apache/arrow-rs/pull/2048#issuecomment-1195636268

   Benchmark runs are scheduled for baseline = 9c70e4acd3a872c472a11bc12ae76837c1d4aaaa and contender = 0c640544fc484721812267978dd90346264ea000. 0c640544fc484721812267978dd90346264ea000 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/78d79d8053a4436ba5e01861c8b13855...e45656fecf7a488c88b8f15f0750de0f/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/c07018f5c35a475984c188b8324918e0...35fc895f39be456f9812a0a14b5ea067/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/b3f2c60a80804955822ef1eeaf82c394...80c7e4b31a014897b4010f49d5d7b88a/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/909c5c8b2071448288c8eedf9b57807a...6e30cd43c7bb4ae7b7ddf5d1cc0cf1c9/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #2048: Improve `validate_utf8` performance

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #2048:
URL: https://github.com/apache/arrow-rs/pull/2048#discussion_r928123907


##########
arrow/src/array/data.rs:
##########
@@ -1125,16 +1125,37 @@ impl ArrayData {
         T: ArrowNativeType + TryInto<usize> + num::Num + std::fmt::Display,
     {
         let values_buffer = &self.buffers[1].as_slice();
-
-        self.validate_each_offset::<T, _>(values_buffer.len(), |string_index, range| {
-            std::str::from_utf8(&values_buffer[range.clone()]).map_err(|e| {
-                ArrowError::InvalidArgumentError(format!(
-                    "Invalid UTF8 sequence at string index {} ({:?}): {}",
-                    string_index, range, e
-                ))
-            })?;
-            Ok(())
-        })
+        if let Ok(values_str) = std::str::from_utf8(values_buffer) {
+            // Validate Offsets are correct
+            self.validate_each_offset::<T, _>(
+                values_buffer.len(),
+                |string_index, range| {
+                    if !values_str.is_char_boundary(range.start)
+                        || !values_str.is_char_boundary(range.end)

Review Comment:
   I think you can remove `values_str.is_char_boundary(range.end)`, as the end offset is the start offset of the next string slice. We do not need to check the final offset as if the end of the string is not a valid char boundary, the string as a whole would fail validation.



-- 
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


[GitHub] [arrow-rs] tustvold commented on pull request #2048: Improve `validate_utf8` performance

Posted by GitBox <gi...@apache.org>.
tustvold commented on PR #2048:
URL: https://github.com/apache/arrow-rs/pull/2048#issuecomment-1184446807

   Added a test in #2068 


-- 
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


[GitHub] [arrow-rs] tustvold merged pull request #2048: Improve `validate_utf8` performance

Posted by GitBox <gi...@apache.org>.
tustvold merged PR #2048:
URL: https://github.com/apache/arrow-rs/pull/2048


-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #2048: Improve `validate_utf8` performance

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #2048:
URL: https://github.com/apache/arrow-rs/pull/2048#discussion_r928123907


##########
arrow/src/array/data.rs:
##########
@@ -1125,16 +1125,37 @@ impl ArrayData {
         T: ArrowNativeType + TryInto<usize> + num::Num + std::fmt::Display,
     {
         let values_buffer = &self.buffers[1].as_slice();
-
-        self.validate_each_offset::<T, _>(values_buffer.len(), |string_index, range| {
-            std::str::from_utf8(&values_buffer[range.clone()]).map_err(|e| {
-                ArrowError::InvalidArgumentError(format!(
-                    "Invalid UTF8 sequence at string index {} ({:?}): {}",
-                    string_index, range, e
-                ))
-            })?;
-            Ok(())
-        })
+        if let Ok(values_str) = std::str::from_utf8(values_buffer) {
+            // Validate Offsets are correct
+            self.validate_each_offset::<T, _>(
+                values_buffer.len(),
+                |string_index, range| {
+                    if !values_str.is_char_boundary(range.start)
+                        || !values_str.is_char_boundary(range.end)

Review Comment:
   I think you can remove `values_str.is_char_boundary(range.end)`, as the end offset is the start offset of the next string slice and will therefore be checked by that. We do not need to check the final offset as if the end of the string is not a valid char boundary, the string as a whole would fail validation.



-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #2048: Improve `validate_utf8` performance

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #2048:
URL: https://github.com/apache/arrow-rs/pull/2048#discussion_r930112449


##########
arrow/src/array/data.rs:
##########
@@ -1125,16 +1125,37 @@ impl ArrayData {
         T: ArrowNativeType + TryInto<usize> + num::Num + std::fmt::Display,
     {
         let values_buffer = &self.buffers[1].as_slice();
-
-        self.validate_each_offset::<T, _>(values_buffer.len(), |string_index, range| {
-            std::str::from_utf8(&values_buffer[range.clone()]).map_err(|e| {
-                ArrowError::InvalidArgumentError(format!(
-                    "Invalid UTF8 sequence at string index {} ({:?}): {}",
-                    string_index, range, e
-                ))
-            })?;
-            Ok(())
-        })
+        if let Ok(values_str) = std::str::from_utf8(values_buffer) {
+            // Validate Offsets are correct
+            self.validate_each_offset::<T, _>(
+                values_buffer.len(),
+                |string_index, range| {
+                    if !values_str.is_char_boundary(range.start)
+                        || !values_str.is_char_boundary(range.end)

Review Comment:
   I realized an additional subtlety with this, if the offsets buffer is sliced, you need to validate that this slicing is at a valid boundary, which a naive implementation of the above might miss.
   
   Theoretically you only need to validate the range of values covered by the offsets, which might be another possible optimisation :thinking:  



-- 
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


[GitHub] [arrow-rs] codecov-commenter commented on pull request #2048: Improve `validate_utf8` performance

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #2048:
URL: https://github.com/apache/arrow-rs/pull/2048#issuecomment-1189658946

   # [Codecov](https://codecov.io/gh/apache/arrow-rs/pull/2048?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#2048](https://codecov.io/gh/apache/arrow-rs/pull/2048?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (a17f650) into [master](https://codecov.io/gh/apache/arrow-rs/commit/b2cf02c7a8a5027d037fc359323bc0ed45b943de?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b2cf02c) will **increase** coverage by `0.00%`.
   > The diff coverage is `77.77%`.
   
   > :exclamation: Current head a17f650 differs from pull request most recent head 17678fa. Consider uploading reports for the commit 17678fa to get more accurate results
   
   ```diff
   @@           Coverage Diff           @@
   ##           master    #2048   +/-   ##
   =======================================
     Coverage   83.74%   83.74%           
   =======================================
     Files         225      225           
     Lines       59422    59434   +12     
   =======================================
   + Hits        49764    49775   +11     
   - Misses       9658     9659    +1     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/arrow-rs/pull/2048?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [arrow/src/array/data.rs](https://codecov.io/gh/apache/arrow-rs/pull/2048/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-YXJyb3cvc3JjL2FycmF5L2RhdGEucnM=) | `84.93% <77.77%> (-0.02%)` | :arrow_down: |
   | [parquet/src/encodings/encoding.rs](https://codecov.io/gh/apache/arrow-rs/pull/2048/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGFycXVldC9zcmMvZW5jb2RpbmdzL2VuY29kaW5nLnJz) | `93.62% <0.00%> (+0.19%)` | :arrow_up: |
   
   


-- 
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


[GitHub] [arrow-rs] tfeda commented on pull request #2048: Improve `validate_utf8` performance

Posted by GitBox <gi...@apache.org>.
tfeda commented on PR #2048:
URL: https://github.com/apache/arrow-rs/pull/2048#issuecomment-1189650501

   Sorry for the late follow-up, I see its purpose now and added it.


-- 
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