Skip to content

Unreachable case analysis in pattern matcher is allocation heavy #491

Closed
@retronym

Description

@retronym

This stack has shown up as a leading allocation source in the compiler under some workloads:

Object scala.tools.nsc.transform.patmat.Solving$Solver.$anonfun$dropUnit$1(...)	219
   Object scala.tools.nsc.transform.patmat.Solving$Solver$$Lambda$2842.268435976.apply(...)	219
   void scala.collection.IndexedSeqOptimized.foreach(...)	219
   void scala.collection.IndexedSeqOptimized.foreach$(...)	219
   void scala.collection.mutable.ArrayOps$ofRef.foreach(...)	219
   Set[] scala.tools.nsc.transform.patmat.Solving$Solver.dropUnit(...)	219
   Set scala.tools.nsc.transform.patmat.Solving$Solver.findTseitinModel0(...)	219
   Set scala.tools.nsc.transform.patmat.Solving$Solver.findTseitinModelFor(...)	219
   Set scala.tools.nsc.transform.patmat.Solving$Solver.findTseitinModelFor$(...)	219
   Set scala.tools.nsc.transform.patmat.PatternMatching$OptimizingMatchTranslator.findTseitinModelFor(...)	219
   Map scala.tools.nsc.transform.patmat.Solving$Solver.findModelFor(...)	219
   Map scala.tools.nsc.transform.patmat.Solving$Solver.findModelFor$(...)	219
   Map scala.tools.nsc.transform.patmat.PatternMatching$OptimizingMatchTranslator.findModelFor(...)	219
   Map scala.tools.nsc.transform.patmat.PatternMatching$OptimizingMatchTranslator.findModelFor(...)	219
   Option scala.tools.nsc.transform.patmat.MatchAnalysis$MatchAnalyzer.unreachableCase(...)	219

Tasks:

  • Use a debugger / logging to characterize the pattern of data that arrives in dropUnit, and relate this back to patterns of source code.
  • As a diagnostics, add a counter of the total number of bytes allocated by simplified.toArray in that method.
  • Synthesize a test case that can demonstrate that this number grows O(N^2) or worse with respect to the complexity of the source code.
  • Devise a more efficient implementation. Could we make dropUnit mutate an Array[Clause] in place to insert nulls, rather than returning a new, smaller array?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions