immutable Bag is too slow in a benchmark (linked) #8
Description
Hi @nicolasstucki! You might remember me from previous issues this week, and because we met at some conference (IIRC, Scala 2013).
I'm giving so many comments because I'm experimenting with some implementations of immutable bags, including something I quickly hacked together, and yours, and right now I have an example which appears much slower with your implementation. I don't claim it's necessarily because of your library — I'm using it for atypical needs and in atypical ways, but maybe you're interested in taking a look.
Furthermore, almost all examples are much (100x) slower with bags (either implementation) than with lists, though I hope this can be avoided. That's why I took a look at your library.
I'm still examining the first benchmark I wrote:
def nestedLoopBags1(coll1: Bag[Int], coll2: Bag[Int]): Bag[Int] =
for {
i <- coll1
j <- coll2
} yield (i * N + j)
In fact, I'm studying the performance of some equivalent variants, including variants which re-execute incrementally only some operations when the inputs change.
I haven't properly profiled the execution time, so I don't know yet what's the cause of the slowdown, but I expect that #7 is involved.
To reproduce
I'm afraid the code isn't properly commented yet; but anyway:
- Checkout https://github.com/inc-lc/ilc-scala
- run sbt
- at the sbt prompt, run
testOnly ilc.examples.handwritten.NestedLoop1Bench
. - Notice that
nestedLoopBags3Incr
is no faster than other bag operations, and that all bag benchmarks (Bag) are 100x slower than non-bag-benchmarks (those without Bag in the name). - Switch to branch
topic/homegrown-bag-tune
(with a hand-crafted implementation of some Bag operations) and compare performance.