-
Notifications
You must be signed in to change notification settings - Fork 396
Allocate all emitter var field strings statically #4911
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
Conversation
Based on #4909 due to merge conflicts. |
Dispatchers are the only place where we pass a dynamically computed string to the VarGen subsystem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. I only have a few comments, most of them typos.
* | ||
* Also gives us additional compile-time safety against typos. | ||
*/ | ||
private[emitter] final class VarFld private (val str: String) extends AnyVal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to call this VarField
in full?
private[emitter] final class VarFld private (val str: String) extends AnyVal | |
private[emitter] final class VarField private (val str: String) extends AnyVal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only brevity. And it's true that saving 2 chars is likely not worth the additional abbreviation.
private[emitter] final class VarFld private (val str: String) extends AnyVal | ||
|
||
object VarFld { | ||
def mk(str: String): VarFld = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def mk(str: String): VarFld = { | |
private def mk(str: String): VarFld = { |
/** Scala class constructors (<init>). */ | ||
final val ct = mk("$ct") | ||
|
||
/** Scala class initializers (<cinit>). */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** Scala class initializers (<cinit>). */ | |
/** Scala class initializers (<clinit>). */ |
/** Scala module accessor. */ | ||
final val m = mk("$m") | ||
|
||
/** Var / let to store Scala module instnance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** Var / let to store Scala module instnance. | |
/** Var / let to store Scala module instance. |
/** Class data. */ | ||
final val d = mk("$d") | ||
|
||
/** inInstanceOf functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** inInstanceOf functions. | |
/** isInstanceOf functions. |
|
||
final val moduleDefault = mk("$moduleDefault") | ||
|
||
// Arithemtic Call Helpers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Arithemtic Call Helpers | |
// Arithmetic Call Helpers |
I have addressed all the comments. I have also added |
Memory profile analysis shows ~120k duplicates of the string "$n" amounting to ~6MB waste (on the test suite).
Further digging revealed that this happens through the "$n" call-helper (null check) via:
By defining the relevant strings statically (including the leading
$
), we avoid the duplication.Discovered while working on #4906.