Skip to content

Typer + Inferencer need to lose some weight #501

Open
@retronym

Description

@retronym

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions