Skip to content

Typer + Inferencer need to lose some weight #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
retronym opened this issue May 9, 2018 · 3 comments
Open

Typer + Inferencer need to lose some weight #501

retronym opened this issue May 9, 2018 · 3 comments
Assignees
Milestone

Comments

@retronym
Copy link
Member

retronym commented May 9, 2018

Before:

 java -Djol.tryWithSudo=true -cp $(coursier fetch -q -p 'org.openjdk.jol:jol-cli:0.9') org.openjdk.jol.Main internals -cp /usr/local/Cellar/scala/2.12.5/libexec/lib/jline-2.14.5.jar:/usr/local/Cellar/scala/2.12.5/libexec/lib/scala-compiler.jar:/usr/local/Cellar/scala/2.12.5/libexec/lib/scala-library.jar:/usr/local/Cellar/scala/2.12.5/libexec/lib/scala-parser-combinators_2.12-1.0.7.jar:/usr/local/Cellar/scala/2.12.5/libexec/lib/scala-reflect.jar:/usr/local/Cellar/scala/2.12.5/libexec/lib/scala-swing_2.12-2.0.0.jar:/usr/local/Cellar/scala/2.12.5/libexec/lib/scala-xml_2.12-1.0.6.jar:/usr/local/Cellar/scala/2.12.5/libexec/lib/scalap-2.12.5.jar 'scala.tools.nsc.typechecker.Typers$Typer' 'scala.tools.nsc.typechecker.Typers$Typer$$anon$2'
objc[21400]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java (0x1023124c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10a0394e0). One of the two will be used. Which one is undefined.
# Running 64-bit HotSpot VM.
# Using compressed oop with 3-bit shift.
# Using compressed klass with 3-bit shift.
# Objects are 8 bytes aligned.
# Field sizes by type: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]
# Array element sizes: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]

Failed to find matching constructor, falling back to class-only introspection.

scala.tools.nsc.typechecker.Typers$Typer object internals:
 OFFSET  SIZE                                                                          TYPE DESCRIPTION                                                  VALUE
      0    12                                                                               (object header)                                              N/A
     12     4                     scala.tools.nsc.typechecker.Typers.Typer.checkNoEscaping$ Typer.checkNoEscaping$module                                 N/A
     16     4                                scala.tools.nsc.typechecker.Typers.Typer.dyna$ Typer.dyna$module                                            N/A
     20     4                                  scala.tools.nsc.typechecker.Contexts.Context Typer.context0                                               N/A
     24     4            scala.reflect.internal.Definitions.DefinitionsClass.RunDefinitions Typer.runDefinitions                                         N/A
     28     4                                                  scala.collection.mutable.Map Typer.transformed                                            N/A
     32     4                                  scala.tools.nsc.typechecker.Infer.Inferencer Typer.infer                                                  N/A
     36     4                                      scala.tools.nsc.typechecker.Namers.Namer Typer.namerCache                                             N/A
     40     4                                  scala.tools.nsc.typechecker.Contexts.Context Typer.context                                                N/A
     44     4   scala.tools.nsc.typechecker.ContextErrors.TyperContextErrors.TyperErrorGen$ Typer.TyperErrorGen$module                                   N/A
     48     4            scala.reflect.internal.Definitions.DefinitionsClass.RunDefinitions Typer.scala$tools$nsc$typechecker$Tags$Tag$$runDefinitions   N/A
     52     4     scala.tools.nsc.typechecker.TypeDiagnostics.TyperDiagnostics.checkUnused$ Typer.checkUnused$module                                     N/A
     56     4       scala.tools.nsc.typechecker.TypeDiagnostics.TyperDiagnostics.checkDead$ Typer.checkDead$module                                       N/A
     60     4                                          scala.tools.nsc.typechecker.Analyzer Typer.$outer                                                 N/A
Instance size: 64 bytes
Space losses: 0 bytes internal + 0 bytes external = 0 bytes total

Failed to find matching constructor, falling back to class-only introspection.

scala.tools.nsc.typechecker.Typers$Typer$$anon$2 object internals:
 OFFSET  SIZE                                                                               TYPE DESCRIPTION                               VALUE
      0    12                                                                                    (object header)                           N/A
     12     4                     scala.tools.nsc.typechecker.Infer.Inferencer.AdjustedTypeArgs$ Inferencer.AdjustedTypeArgs$module        N/A
     16     4                             scala.tools.nsc.typechecker.Infer.Inferencer.toOrigin$ Inferencer.toOrigin$module                N/A
     20     4                 scala.tools.nsc.typechecker.Infer.Inferencer.approximateAbstracts$ Inferencer.approximateAbstracts$module    N/A
     24     4   scala.tools.nsc.typechecker.ContextErrors.InferencerContextErrors.InferErrorGen$ Inferencer.InferErrorGen$module           N/A
     28     4                                               scala.tools.nsc.typechecker.Analyzer Inferencer.$outer                         N/A
     32     4                                           scala.tools.nsc.typechecker.Typers.Typer Typers$Typer$$anon$2.$outer               N/A
     36     4                                                                                    (loss due to the next object alignment)
Instance size: 40 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total

After faster/typer-diet

/code/scala on faster/typer-diet*
$ java -Djol.tryWithSudo=true -cp $(coursier fetch -q -p 'org.openjdk.jol:jol-cli:0.9') org.openjdk.jol.Main internals -cp build/quick/classes/compiler:build/quick/classes/reflect:build/quick/classes/library 'scala.tools.nsc.typechecker.Typers$Typer'
objc[21421]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java (0x10ce884c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x1132274e0). One of the two will be used. Which one is undefined.
# Running 64-bit HotSpot VM.
# Using compressed oop with 3-bit shift.
# Using compressed klass with 3-bit shift.
# Objects are 8 bytes aligned.
# Field sizes by type: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]
# Array element sizes: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]

Failed to find matching constructor, falling back to class-only introspection.

scala.tools.nsc.typechecker.Typers$Typer object internals:
 OFFSET  SIZE                                           TYPE DESCRIPTION                               VALUE
      0    12                                                (object header)                           N/A
     12     4       scala.tools.nsc.typechecker.Namers.Namer Typer.namerCache                          N/A
     16     4   scala.tools.nsc.typechecker.Contexts.Context Typer.context                             N/A
     20     4           scala.tools.nsc.typechecker.Analyzer Typer.$outer                              N/A
Instance size: 24 bytes
Space losses: 0 bytes internal + 0 bytes external = 0 bytes total

Yep, 24 bytes rather than the hulking 104 we're currently hauling around.

As a bonus, we can avoid allocating Typer-s altogether in TypingTransformers.

We'll need a followup ticket to give Context the same treatment, its still a monster.

@retronym retronym changed the title Typer + Infererence needs to lose some weight Typer + Inferencer needs to lose some weight May 9, 2018
@retronym retronym self-assigned this May 9, 2018
@retronym retronym changed the title Typer + Inferencer needs to lose some weight Typer + Inferencer need to lose some weight May 9, 2018
@retronym
Copy link
Member Author

retronym commented May 9, 2018

I estimate this can reduce allocation by 3-4% overall.

@retronym
Copy link
Member Author

Here's the followup work for Context: https://github.com/retronym/scala/tree/topic/post-typer-context

retronym added a commit to retronym/scala that referenced this issue May 11, 2018
  - Move the checkDead module out of Typer
  - Use a new bit in ContextMode to track when to suppress
    the warning, rather than maintaining the stack of the
    symbols of enclosing applications
  - Only do any of this when under -Ywarn-dead code

References scala/scala-dev#501
retronym added a commit to retronym/scala that referenced this issue May 11, 2018
  - Move the checkDead module out of Typer
  - Use a new bit in ContextMode to track when to suppress
    the warning, rather than maintaining the stack of the
    symbols of enclosing applications
  - Only do any of this when under -Ywarn-dead code

References scala/scala-dev#501
retronym added a commit to retronym/scala that referenced this issue Jun 8, 2018
  - Move the checkDead module out of Typer
  - Use a new bit in ContextMode to track when to suppress
    the warning, rather than maintaining the stack of the
    symbols of enclosing applications
  - Only do any of this when under -Ywarn-dead code

References scala/scala-dev#501

(cherry picked from commit fc72bbb)
@dwijnand
Copy link
Member

dwijnand commented Nov 4, 2020

Looks like there were a few PRs addressing this, but not all of it? Jason describes in scala/scala#6616:

A followup PR will build upon this to remove the *ErrorGenFields and
collapse Typer and Inferencer into a single class.

Which looks like are still TODO.

@dwijnand dwijnand added this to the Backlog milestone Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants