This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.11 by this push:
     new 34bf11136 AVRO-4007: [rust] Faster `is_nullable` for UnionSchema 
(#2961)
34bf11136 is described below

commit 34bf111368cebf6ae5a772b4223c77392dde5614
Author: John Emhoff <[email protected]>
AuthorDate: Mon Jun 24 04:05:17 2024 -0400

    AVRO-4007: [rust] Faster `is_nullable` for UnionSchema (#2961)
    
    * Faster `is_nullable` for UnionSchema
    
    I'm writing several gigabytes of Avro and noticed that it seems
    oddly slow. I ran a profile and noticed that about 25% of my total
    run time was being spent in `UnionSchema::is_nullable`.
    
    It looks like what's happening is that the test `x == Schema::Null`
    is slow because the equality test involves a schema canonicalization.
    
    I've updated the match to match against Schema::Null instead and see
    a significant performance increase.
    
    * Fix formatting
    
    * Apply clippy suggestion
    
    Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
    
    ---------
    
    Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
    Co-authored-by: Martin Grigorov <[email protected]>
    Co-authored-by: Martin Tzvetanov Grigorov <[email protected]>
    (cherry picked from commit 4eda118a42f930bdc6f463621e2a6450098cbfe7)
---
 lang/rust/avro/src/schema.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lang/rust/avro/src/schema.rs b/lang/rust/avro/src/schema.rs
index e3031f8fb..c313fe5f3 100644
--- a/lang/rust/avro/src/schema.rs
+++ b/lang/rust/avro/src/schema.rs
@@ -902,7 +902,7 @@ impl UnionSchema {
 
     /// Returns true if the any of the variants of this `UnionSchema` is 
`Null`.
     pub fn is_nullable(&self) -> bool {
-        !self.schemas.is_empty() && self.schemas.iter().any(|s| s == 
&Schema::Null)
+        self.schemas.iter().any(|x| matches!(x, Schema::Null))
     }
 
     /// Optionally returns a reference to the schema matched by this value, as 
well as its position

Reply via email to