Skip to content

Commit

Permalink
ml/params: cache stringified versions of Params
Browse files Browse the repository at this point in the history
repeated lookup of paramter values within ParamMaps was causing
a significant (35-45%) performance hit within LogisticRegression
(SPARK-13132) due to the string interpolation performed by every
call to hashCode.

cache the stringified representation of the Param in a private
instance variable, so that the string interpolation only happens
once
  • Loading branch information
idigary committed Feb 2, 2016
1 parent 895facf commit 6790e35
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mllib/src/main/scala/org/apache/spark/ml/param/params.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ class Param[T](val parent: String, val name: String, val doc: String, val isVali
}
}

override final def toString: String = s"${parent}__$name"
private[this] val stringRepresentation = s"${parent}__$name"

override final def toString: String = stringRepresentation

override final def hashCode: Int = toString.##

Expand Down

0 comments on commit 6790e35

Please sign in to comment.