Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize QTree a bunch #475

Merged
merged 3 commits into from
Aug 3, 2015

Conversation

ianoc
Copy link
Collaborator

@ianoc ianoc commented Jul 30, 2015

  1. Internally use nullable instances of QTree rather than Option[QTree].
  2. Specialize the class
  3. Pre build an array with the range values rather than calculating pow(2, level) on each instanciation

Performance numbers:

Develop::
[info] Benchmark (depthK) (numElements) Mode Cnt Score Error Units
[info] QTreeBenchmark.timePlusDouble 6 10000 avgt 15 49604065.294 ± 343946.724 ns/op
[info] QTreeBenchmark.timePlusLong 6 10000 avgt 15 54040361.060 ± 451564.394 ns/op
[info] QTreeBenchmark.timePlusUnit 6 10000 avgt 15 52363803.668 ± 1403481.464 ns/op
[info] QTreeBenchmark.timeSumOptionDouble 6 10000 avgt 15 18536550.306 ± 102450.054 ns/op
[info] QTreeBenchmark.timeSumOptionLong 6 10000 avgt 15 14265313.429 ± 80999.618 ns/op
[info] QTreeBenchmark.timeSumOptionUnit 6 10000 avgt 15 14109388.526 ± 139901.693 ns/op

Branch::

[info] Benchmark (depthK) (numElements) Mode Cnt Score Error Units
[info] QTreeBenchmark.timePlusDouble 6 10000 avgt 15 36130358.089 ± 344895.234 ns/op
[info] QTreeBenchmark.timePlusLong 6 10000 avgt 15 40619584.216 ± 213205.614 ns/op
[info] QTreeBenchmark.timePlusUnit 6 10000 avgt 15 35111406.421 ± 175324.238 ns/op
[info] QTreeBenchmark.timeSumOptionDouble 6 10000 avgt 15 8657591.363 ± 148336.269 ns/op
[info] QTreeBenchmark.timeSumOptionLong 6 10000 avgt 15 5310313.465 ± 88287.513 ns/op
[info] QTreeBenchmark.timeSumOptionUnit 6 10000 avgt 15 4735604.540 ± 45094.848 ns/op

@ianoc
Copy link
Collaborator Author

ianoc commented Jul 31, 2015

qtreebenchmark

}

class QTreeSemigroup[A](k: Int)(implicit val underlyingMonoid: Monoid[A]) extends Semigroup[QTree[A]] {
class QTreeSemigroup[@specialized(Int, Long, Float, Double, Unit) A](k: Int)(implicit val underlyingMonoid: Monoid[A]) extends Semigroup[QTree[A]] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the Unit? There is only one value, so I assume boxing is fast. If we specialize on it, we get an additional copy of all the methods with type parameters, which adds to the jar size.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, will remove

@avibryant
Copy link
Contributor

A+++ would write unoptimized code for ianoc to make much better again.

@ianoc ianoc force-pushed the ianoc/qTreeBenchmarkMoreCoverage branch from 3bb335a to fd9f4db Compare July 31, 2015 22:50
Heavily driven by benchmarks. Avoid allocations, dealing with options or similar. Attempt to keep as much external  source compatibility as possible
…t erased than the old constructor. Add the old constructor as an overloaded constructor so that we can keep our binary compatibility to a minimum

We now are just missing copy constructors:

[error]  * synthetic method copy$default$6()scala.Option in class com.twitter.algebird.QTree does not have a correspondent in new version
[error]    filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.copy$default$6")
[error]  * synthetic method com$twitter$algebird$QTree$$findRankUpperBound(Long)scala.Option in class com.twitter.algebird.QTree does not have a correspondent in new version
[error]    filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.com$twitter$algebird$QTree$$findRankUpperBound")
[error]  * synthetic method copy$default$2()Int in class com.twitter.algebird.QTree does not have a correspondent in new version
[error]    filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.copy$default$2")
[error]  * synthetic method copy$default$5()scala.Option in class com.twitter.algebird.QTree does not have a correspondent in new version
[error]    filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.copy$default$5")
[error]  * synthetic method com$twitter$algebird$QTree$$findRankLowerBound(Long)scala.Option in class com.twitter.algebird.QTree does not have a correspondent in new version
[error]    filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.com$twitter$algebird$QTree$$findRankLowerBound")
[error]  * method copy(Long,Int,Long,java.lang.Object,scala.Option,scala.Option)com.twitter.algebird.QTree in class com.twitter.algebird.QTree does not have a correspondent in new version
[error]    filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.copy")
[error]  * synthetic method copy$default$1()Long in class com.twitter.algebird.QTree does not have a correspondent in new version
[error]    filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.copy$default$1")
[error]  * synthetic method copy$default$4()java.lang.Object in class com.twitter.algebird.QTree does not have a correspondent in new version
[error]    filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.copy$default$4")
[error]  * synthetic method copy$default$3()Long in class com.twitter.algebird.QTree does not have a correspondent in new version
[error]    filter with: ProblemFilters.exclude[MissingMethodProblem]("com.twitter.algebird.QTree.copy$default$3")
java.lang.RuntimeException: algebird-core: Binary compatibility check failed!

Do we mind that?
@@ -155,7 +243,7 @@ case class QTree[A](
ancestorLevel += 1
offsetDiff >>= 1
}
ancestorLevel.max(level).max(other.level)
ancestorLevel.max(_level).max(other.level)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use scala.math.max here to prevent boxing/unboxing?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

johnynek added a commit that referenced this pull request Aug 3, 2015
@johnynek johnynek merged commit 2c419f2 into ianoc/qTreeBenchmarkMoreCoverage Aug 3, 2015
@johnynek johnynek deleted the ianoc/optimizeQTree branch August 3, 2015 17:37
@ianoc
Copy link
Collaborator Author

ianoc commented Aug 3, 2015

@avibryant Any time! I never have the time to play with new algo's. But once our jobs go slow lots of motivation to improve things! :)

@ianoc ianoc restored the ianoc/optimizeQTree branch August 4, 2015 00:31
@ianoc ianoc deleted the ianoc/optimizeQTree branch August 4, 2015 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants