Skip to content

Commit 8a14de3

Browse files
authored
-Yprofile-trace profiles all inline calls (#23490)
Previously we only profiled macro expansion, but even non-macro inline calls can have a significant impact on performance (e.g. if we're doing typeclass derivation) and are worth tracking. This does not seem to significantly impact the size of traces in practice.
1 parent 2660b09 commit 8a14de3

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

compiler/src/dotty/tools/dotc/inlines/Inliner.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,8 +1146,7 @@ class Inliner(val call: tpd.Tree)(using Context):
11461146

11471147
val evaluatedSplice =
11481148
inContext(quoted.MacroExpansion.context(inlinedFrom)):
1149-
ctx.profiler.onMacroSplice(inlinedFrom.symbol):
1150-
Splicer.splice(body, splicePos, inlinedFrom.srcPos, MacroClassLoader.fromContext)
1149+
Splicer.splice(body, splicePos, inlinedFrom.srcPos, MacroClassLoader.fromContext)
11511150
val inlinedNormalizer = new TreeMap {
11521151
override def transform(tree: tpd.Tree)(using Context): tpd.Tree = tree match {
11531152
case tree @ Inlined(_, Nil, expr) if tree.inlinedFromOuterScope && enclosingInlineds.isEmpty => transform(expr)

compiler/src/dotty/tools/dotc/inlines/Inlines.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ object Inlines:
100100
* @return An `Inlined` node that refers to the original call and the inlined bindings
101101
* and body that replace it.
102102
*/
103-
def inlineCall(tree: Tree)(using Context): Tree =
103+
def inlineCall(tree: Tree)(using Context): Tree = ctx.profiler.onInlineCall(tree.symbol):
104104
if tree.symbol.denot != SymDenotations.NoDenotation
105105
&& tree.symbol.effectiveOwner == defn.CompiletimeTestingPackage.moduleClass
106106
then

compiler/src/dotty/tools/dotc/profile/Profiler.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ sealed trait Profiler {
115115
protected def beforeImplicitSearch(pt: Type): TracedEventId = TracedEventId.Empty
116116
protected def afterImplicitSearch(event: TracedEventId): Unit = ()
117117

118-
inline def onMacroSplice[T](macroSym: Symbol)(inline body: T): T =
119-
val event = beforeMacroSplice(macroSym)
118+
inline def onInlineCall[T](inlineSym: Symbol)(inline body: T): T =
119+
val event = beforeInlineCall(inlineSym)
120120
try body
121-
finally afterMacroSplice(event)
122-
protected def beforeMacroSplice(macroSym: Symbol): TracedEventId = TracedEventId.Empty
123-
protected def afterMacroSplice(event: TracedEventId): Unit = ()
121+
finally afterInlineCall(event)
122+
protected def beforeInlineCall(inlineSym: Symbol): TracedEventId = TracedEventId.Empty
123+
protected def afterInlineCall(event: TracedEventId): Unit = ()
124124

125125
inline def onCompletion[T](root: Symbol, associatedFile: => AbstractFile)(inline body: T): T =
126126
val (event, completionName) = beforeCompletion(root, associatedFile)
@@ -176,7 +176,7 @@ private [profile] class RealProfiler(reporter : ProfileReporter)(using Context)
176176

177177
enum Category:
178178
def name: String = this.toString().toLowerCase()
179-
case Run, Phase, File, TypeCheck, Implicit, Macro, Completion
179+
case Run, Phase, File, TypeCheck, Implicit, Inline, Completion
180180
private [profile] val chromeTrace =
181181
if ctx.settings.YprofileTrace.isDefault
182182
then null
@@ -315,8 +315,8 @@ private [profile] class RealProfiler(reporter : ProfileReporter)(using Context)
315315
override def beforeImplicitSearch(pt: Type): TracedEventId = traceDurationStart(Category.Implicit, s"?[${symbolName(pt.typeSymbol)}]", colour = "yellow")
316316
override def afterImplicitSearch(event: TracedEventId): Unit = traceDurationEnd(Category.Implicit, event, colour = "yellow")
317317

318-
override def beforeMacroSplice(macroSym: Symbol): TracedEventId = traceDurationStart(Category.Macro, s"«${symbolName(macroSym)}»", colour = "olive")
319-
override def afterMacroSplice(event: TracedEventId): Unit = traceDurationEnd(Category.Macro, event, colour = "olive")
318+
override def beforeInlineCall(inlineSym: Symbol): TracedEventId = traceDurationStart(Category.Inline, s"«${symbolName(inlineSym)}»", colour = "olive")
319+
override def afterInlineCall(event: TracedEventId): Unit = traceDurationEnd(Category.Inline, event, colour = "olive")
320320

321321
override def beforeCompletion(root: Symbol, associatedFile: => AbstractFile): (TracedEventId, String) =
322322
if chromeTrace == null

0 commit comments

Comments
 (0)