GitHub user sksamuel opened a pull request:

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

    Replace use of .size with .length for Arrays

    Invoking .size on arrays is valid, but requires an implicit conversion to 
SeqLike. This incurs a compile time overhead and more importantly a runtime 
overhead, as the Array must be wrapped before the method can be invoked. For 
example, the difference in generated byte code is:
    
      public int withSize();
        Code:
           0: getstatic     #23                 // Field 
scala/Predef$.MODULE$:Lscala/Predef$;
           3: aload_0
           4: invokevirtual #25                 // Method array:()[I
           7: invokevirtual #29                 // Method 
scala/Predef$.intArrayOps:([I)Lscala/collection/mutable/ArrayOps;
          10: invokeinterface #34,  1           // InterfaceMethod 
scala/collection/mutable/ArrayOps.size:()I
          15: ireturn
    
      public int withLength();
        Code:
           0: aload_0
           1: invokevirtual #25                 // Method array:()[I
           4: arraylength
           5: ireturn

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

    $ git pull https://github.com/sksamuel/spark master

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

    https://github.com/apache/spark/pull/5376.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 #5376
    
----
commit 77ec261c9c6052d7f5f46fe90a5384aee0c0c362
Author: sksamuel <[email protected]>
Date:   2015-04-06T21:18:24Z

    Replace use of .size with .length for Arrays.
    
    Invoking .size on arrays is valid, but requires an implicit conversion to 
SeqLike. This incurs a compile time overhead and more importantly a runtime 
overhead, as the Array must be wrapped before the method can be invoked. For 
example, the difference in generated byte code is:
    
      public int withSize();
        Code:
           0: getstatic     #23                 // Field 
scala/Predef$.MODULE$:Lscala/Predef$;
           3: aload_0
           4: invokevirtual #25                 // Method array:()[I
           7: invokevirtual #29                 // Method 
scala/Predef$.intArrayOps:([I)Lscala/collection/mutable/ArrayOps;
          10: invokeinterface #34,  1           // InterfaceMethod 
scala/collection/mutable/ArrayOps.size:()I
          15: ireturn
    
      public int withLength();
        Code:
           0: aload_0
           1: invokevirtual #25                 // Method array:()[I
           4: arraylength
           5: ireturn

----


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