[
https://issues.apache.org/jira/browse/SPARK-17331?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15591204#comment-15591204
]
Apache Spark commented on SPARK-17331:
--------------------------------------
User 'zhengruifeng' has created a pull request for this issue:
https://github.com/apache/spark/pull/15564
> Avoid allocating 0-length arrays
> --------------------------------
>
> Key: SPARK-17331
> URL: https://issues.apache.org/jira/browse/SPARK-17331
> Project: Spark
> Issue Type: Improvement
> Components: MLlib, Spark Core
> Affects Versions: 2.0.0
> Reporter: Sean Owen
> Assignee: Sean Owen
> Priority: Trivial
> Fix For: 2.1.0
>
>
> I've noticed a number of places in the code that allocate 0-length arrays.
> Since all 0-length arrays of a type are equivalent, it's often possible to
> avoid these allocations.
> Where it actually likely matters is {{UTF8String}}, which does it in a
> several places and which can even be replaced by {{UTF8String.EMPTY_UTF8}},
> saving even more allocations.
> It _could_ be worth refactoring other occurrences, mostly of "new byte[0]",
> to simply use a reference to one fixed static instance of it. But I avoided
> that in the Java code on the grounds that it's a little clunky and can be
> added if it proves to be a hotspot.
> Same in Scala, where {{Array[T]()}} can be replaced by {{Array.empty}}. This
> actually still allocates a 0-length array. However the former call actually
> allocates *two* empty arrays because of varargs. The latter is simpler and
> widely used in the code, so, seems worth touching up to save some garbage.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]