summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-04-24 10:53:20 +0200
committerJason Zaugg <jzaugg@gmail.com>2014-05-08 10:33:45 +0200
commitb154269b0e7447cfbf7fdb73c8c4efcdca545b11 (patch)
tree662076793ed1333d8d0393efac365f9fe3cd80b9 /src
parentaa3a3dd6a420f57b0fe815bfcb2b23fbb4284468 (diff)
downloadscala-b154269b0e7447cfbf7fdb73c8c4efcdca545b11.tar.gz
scala-b154269b0e7447cfbf7fdb73c8c4efcdca545b11.tar.bz2
scala-b154269b0e7447cfbf7fdb73c8c4efcdca545b11.zip
SI-8531 Better space efficiency for patmat analysis
By adding logging to `clause`, I found that the majority of calls provide 0 or 1 elements. In SI-7020 / 69557da55, we changed this method to use a `LinkedHashSet` to have deterministic results for clauses with more elements. But I suspect that this contributes to higher memory usage from the pattern matcher. The enclosed test case, carefully whittled down by @oxbowlakes, used to consume an inordinate amount of memory and time. After this patch, it is back to 2.10.4 performance. I have run `neg/t7020.scala` in a loop and it still is deterministic.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/transform/patmat/Solving.scala8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/Solving.scala b/src/compiler/scala/tools/nsc/transform/patmat/Solving.scala
index 1902606d86..31b1ffa912 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/Solving.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/Solving.scala
@@ -29,8 +29,12 @@ trait Solving extends Logic {
type Clause = collection.Set[Lit]
// a clause is a disjunction of distinct literals
def clause(l: Lit*): Clause = (
- // neg/t7020.scala changes output 1% of the time, the non-determinism is quelled with this linked set
- mutable.LinkedHashSet(l: _*)
+ if (l.lengthCompare(1) <= 0) {
+ l.toSet // SI-8531 Avoid LinkedHashSet's bulk for 0 and 1 element clauses
+ } else {
+ // neg/t7020.scala changes output 1% of the time, the non-determinism is quelled with this linked set
+ mutable.LinkedHashSet(l: _*)
+ }
)
type Lit