summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVlad Ureche <vlad.ureche@gmail.com>2012-07-10 21:25:45 +0200
committerVlad Ureche <vlad.ureche@gmail.com>2012-07-16 23:41:44 +0200
commit740361b8ae5e9ac8c545b0be878bcae06070dcf0 (patch)
tree4e1fee9851e4ef3d88b5e42d1ead3ffd1d25912e
parentdc70d1b7bd193ff42e9bed5d80f632cffb85a667 (diff)
downloadscala-740361b8ae5e9ac8c545b0be878bcae06070dcf0.tar.gz
scala-740361b8ae5e9ac8c545b0be878bcae06070dcf0.tar.bz2
scala-740361b8ae5e9ac8c545b0be878bcae06070dcf0.zip
Scaladoc: Reducing the memory footprint
- diagrams are not stored because they create many TypeEntities, nodes and edges -- now they are created on demand, so make sure you don't demand them twice! - eliminated the type entity cache, which was nearly useless (6s gain) but was preventing the GC from eliminating TypeEntities - an unsuccessful attempt at reducing the tons of :: garbage we're generating - there's 200MB-250MB of ::s during a typical 'ant docs.lib'
-rw-r--r--src/compiler/scala/tools/nsc/doc/DocFactory.scala1
-rw-r--r--src/compiler/scala/tools/nsc/doc/html/page/Template.scala26
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala6
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/ModelFactoryTypeSupport.scala30
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/diagram/DiagramFactory.scala5
5 files changed, 31 insertions, 37 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/DocFactory.scala b/src/compiler/scala/tools/nsc/doc/DocFactory.scala
index 9fccc57e44..27a03d5381 100644
--- a/src/compiler/scala/tools/nsc/doc/DocFactory.scala
+++ b/src/compiler/scala/tools/nsc/doc/DocFactory.scala
@@ -101,7 +101,6 @@ class DocFactory(val reporter: Reporter, val settings: doc.Settings) { processor
println("no documentable class found in compilation units")
None
}
-
}
object NoCompilerRunException extends ControlThrowable { }
diff --git a/src/compiler/scala/tools/nsc/doc/html/page/Template.scala b/src/compiler/scala/tools/nsc/doc/html/page/Template.scala
index cfd50db99f..417bfcfb96 100644
--- a/src/compiler/scala/tools/nsc/doc/html/page/Template.scala
+++ b/src/compiler/scala/tools/nsc/doc/html/page/Template.scala
@@ -601,13 +601,13 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp
}
val typeHierarchy = if (s.docDiagrams.isSetByUser) mbr match {
- case dtpl: DocTemplateEntity if isSelf && !isReduced && dtpl.inheritanceDiagram.isDefined =>
+ case dtpl: DocTemplateEntity if isSelf && !isReduced =>
makeDiagramHtml(dtpl, dtpl.inheritanceDiagram, "Type Hierarchy", "inheritance-diagram")
case _ => NodeSeq.Empty
} else NodeSeq.Empty // diagrams not generated
val contentHierarchy = if (s.docDiagrams.isSetByUser) mbr match {
- case dtpl: DocTemplateEntity if isSelf && !isReduced && dtpl.contentDiagram.isDefined =>
+ case dtpl: DocTemplateEntity if isSelf && !isReduced =>
makeDiagramHtml(dtpl, dtpl.contentDiagram, "Content Hierarchy", "content-diagram")
case _ => NodeSeq.Empty
} else NodeSeq.Empty // diagrams not generated
@@ -916,16 +916,18 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp
}
def makeDiagramHtml(tpl: DocTemplateEntity, diagram: Option[Diagram], description: String, id: String) = {
- val s = universe.settings
- val diagramSvg = generator.generate(diagram.get, tpl, this)
- if (diagramSvg != NodeSeq.Empty) {
- <div class="toggleContainer block diagram-container" id={ id + "-container"}>
- <span class="toggle diagram-link">{ description }</span>
- <a href="http://docs.scala-lang.org/overviews/scaladoc/usage.html#diagrams" target="_blank" class="diagram-help">Learn more about scaladoc diagrams</a>
- <div class="diagram" id={ id }>{
- diagramSvg
- }</div>
- </div>
+ if (diagram.isDefined) {
+ val s = universe.settings
+ val diagramSvg = generator.generate(diagram.get, tpl, this)
+ if (diagramSvg != NodeSeq.Empty) {
+ <div class="toggleContainer block diagram-container" id={ id + "-container"}>
+ <span class="toggle diagram-link">{ description }</span>
+ <a href="http://docs.scala-lang.org/overviews/scaladoc/usage.html#diagrams" target="_blank" class="diagram-help">Learn more about scaladoc diagrams</a>
+ <div class="diagram" id={ id }>{
+ diagramSvg
+ }</div>
+ </div>
+ } else NodeSeq.Empty
} else NodeSeq.Empty
}
}
diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala
index 2642551aa8..d3d229d848 100644
--- a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala
@@ -449,9 +449,9 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
case _ => None
}
- // We make the diagram a lazy val, since we're not sure we'll include the diagrams in the page
- lazy val inheritanceDiagram = makeInheritanceDiagram(this)
- lazy val contentDiagram = makeContentDiagram(this)
+ // These are generated on-demand, make sure you don't call them more than once
+ def inheritanceDiagram = makeInheritanceDiagram(this)
+ def contentDiagram = makeContentDiagram(this)
}
abstract class PackageImpl(sym: Symbol, inTpl: PackageImpl) extends DocTemplateImpl(sym, inTpl) with Package {
diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactoryTypeSupport.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactoryTypeSupport.scala
index 5efae3257c..d2a26d1309 100644
--- a/src/compiler/scala/tools/nsc/doc/model/ModelFactoryTypeSupport.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactoryTypeSupport.scala
@@ -30,8 +30,7 @@ trait ModelFactoryTypeSupport {
import definitions.{ ObjectClass, NothingClass, AnyClass, AnyValClass, AnyRefClass }
import rootMirror.{ RootPackage, RootClass, EmptyPackage }
- protected var typeCache = new mutable.LinkedHashMap[(Type, TemplateImpl), TypeEntity]
- protected var typeCacheNoPrefix = new mutable.LinkedHashMap[Type, TypeEntity]
+ protected var typeCache = new mutable.LinkedHashMap[Type, TypeEntity]
/** */
def makeType(aType: Type, inTpl: TemplateImpl): TypeEntity = {
@@ -309,21 +308,16 @@ trait ModelFactoryTypeSupport {
// SI-4360: Entity caching depends on both the type AND the template it's in, as the prefixes might change for the
// same type based on the template the type is shown in.
- val cached =
- if (!settings.docNoPrefixes.value)
- typeCache.get((aType, inTpl))
- else
- typeCacheNoPrefix.get(aType)
-
- cached match {
- case Some(typeEntity) => typeEntity
- case None =>
- val typeEntity = createTypeEntity
- if (!settings.docNoPrefixes.value)
- typeCache += (aType, inTpl) -> typeEntity
- else
- typeCacheNoPrefix += aType -> typeEntity
- typeEntity
- }
+ if (settings.docNoPrefixes.value) {
+ val cached = typeCache.get(aType)
+ cached match {
+ case Some(typeEntity) =>
+ typeEntity
+ case None =>
+ val typeEntity = createTypeEntity
+ typeCache += aType -> typeEntity
+ typeEntity
+ }
+ } else createTypeEntity
}
} \ No newline at end of file
diff --git a/src/compiler/scala/tools/nsc/doc/model/diagram/DiagramFactory.scala b/src/compiler/scala/tools/nsc/doc/model/diagram/DiagramFactory.scala
index d0b363854c..9b56509623 100644
--- a/src/compiler/scala/tools/nsc/doc/model/diagram/DiagramFactory.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/diagram/DiagramFactory.scala
@@ -61,9 +61,8 @@ trait DiagramFactory extends DiagramDirectiveParser {
// subclasses
var subclasses: List[Node] =
- tpl.directSubClasses.flatMap {
- case d: TemplateImpl if !classExcluded(d) => List(NormalNode(makeType(d.sym.tpe, tpl), Some(d))())
- case _ => Nil
+ tpl.directSubClasses.collect {
+ case d: TemplateImpl if !classExcluded(d) => NormalNode(makeType(d.sym.tpe, tpl), Some(d))()
}.sortBy(_.tpl.get.name)(implicitly[Ordering[String]].reverse)
// outgoing implicit coversions