rorygraves / scalac_perf

The Scala programming language
http://www.scala-lang.org/
16 stars 3 forks source link

Investigate BatchSourceFile.calculateLineIndices calls #39

Open rorygraves opened 6 years ago

rorygraves commented 6 years ago

In akka-actor BatchSourceFile.calculateLineIndices is called a suprising amount, generating a lot of garbage. From method capture:

invoked.csv:1354209,scala/collection/immutable/Range::scala$collection$immutable$Range$$lastElement()I from scala/reflect/internal/util/BatchSourceFile::calculateLineIndices$1
invoked.csv:1354050,scala/collection/immutable/Range::step()I from scala/reflect/internal/util/BatchSourceFile::calculateLineIndices$1
invoked.csv:36276,scala/collection/mutable/ArrayBuffer::$plus$eq(Ljava/lang/Object;)Lscala/collection/mutable/ArrayBuffer; from scala/reflect/internal/util/BatchSourceFile::$anonfun$lineIndices$1

A quick investigation shows that it is being called from:

java.lang.Throwable
    at scala.reflect.internal.util.BatchSourceFile.lineIndices$lzycompute(SourceFile.scala:158)
    at scala.reflect.internal.util.BatchSourceFile.lineIndices(SourceFile.scala:157)
    at scala.reflect.internal.util.BatchSourceFile.offsetToLine(SourceFile.scala:180)
    at scala.reflect.internal.util.InternalPositionImpl.line(Position.scala:166)
    at scala.reflect.internal.util.InternalPositionImpl.line$(Position.scala:166)
    at scala.reflect.internal.util.Position.line(Position.scala:12)
    at scala.tools.nsc.typechecker.TypeDiagnostics.posPrecedes(TypeDiagnostics.scala:86)
    at scala.tools.nsc.typechecker.TypeDiagnostics.posPrecedes$(TypeDiagnostics.scala:86)
    at scala.tools.nsc.Global$$anon$1.posPrecedes(Global.scala:458)
    at scala.tools.nsc.typechecker.TypeDiagnostics.linePrecedes(TypeDiagnostics.scala:87)
    at scala.tools.nsc.typechecker.TypeDiagnostics.linePrecedes$(TypeDiagnostics.scala:87)
    at scala.tools.nsc.Global$$anon$1.linePrecedes(Global.scala:458)
    at scala.tools.nsc.typechecker.ContextErrors$TyperContextErrors$TyperErrorGen$.addendum$2(ContextErrors.scala:360)
    at scala.tools.nsc.typechecker.ContextErrors$TyperContextErrors$TyperErrorGen$.errMsg$2(ContextErrors.scala:374)
    at scala.tools.nsc.typechecker.ContextErrors$TyperContextErrors$TyperErrorGen$.NotAMemberError(ContextErrors.scala:377)
    at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typed1$1(Typers.scala:4247)
    at scala.reflect.internal.Symbols$Symbol.orElse(Symbols.scala:2533)
    at scala.tools.nsc.typechecker.Typers$Typer.lookupInQualifier$1(Typers.scala:4246)
    at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typed1$55(Typers.scala:4977)
    at scala.Option.getOrElse(Option.scala:121)
    at scala.tools.nsc.typechecker.Typers$Typer.handleMissing$1(Typers.scala:4977)
    at scala.tools.nsc.typechecker.Typers$Typer.typedSelect$1(Typers.scala:4982)
    at scala.tools.nsc.typechecker.Typers$Typer.typedSelectOrSuperCall$1(Typers.scala:5042)
    at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5564)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5580)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5617)
    at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5649)

However whilst an error is generated it is swallowed and never reported (details unknown). If it is not a user level error, we should not be generating the error messages, strings, line numbers etc.

mkeskells commented 6 years ago

I meant to raise that one ....

code around there looks ripe for tuning