GitHub user tpoterba opened a pull request:

    https://github.com/apache/spark/pull/18005

    [SPARK-20773][SQL] ParquetWriteSupport.writeFields is quadratic in number 
of fields 

    Fix quadratic List indexing in ParquetWriteSupport.
    
    I noticed this function while profiling some code with today. It showed up 
as a significant factor in a table with twenty columns; with hundreds of 
columns, it could dominate any other function call.
    
    ## What changes were proposed in this pull request?
    
    The writeFields method iterates from 0 until number of fields, indexing 
into rootFieldWriters for each element. rootFieldWriters is a List, so indexing 
is a linear operation. The complexity of the writeFields method is thus 
quadratic in the number of fields.
    
    Solution: explicitly convert rootFieldWriters to Array (implicitly 
converted to WrappedArray) for constant-time indexing. 
    
    ## How was this patch tested?
    
    This is a one-line change for performance reasons.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/tpoterba/spark tpoterba-patch-1

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/18005.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #18005
    
----
commit e13ce9f85af8a0f87af09e49de04cfda30bf9180
Author: Tim Poterba <[email protected]>
Date:   2017-05-16T19:29:46Z

    Fix quadratic List indexing in ParquetWriteSupport
    
    Fix quadratic List indexing in ParquetWriteSupport.
    
    Minimal solution is to convert rootFieldWriters to a WrappedArray, which 
has O(1) indexing, and restores complexity to linear.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to