10000 Allocate all emitter var field strings statically by gzm0 · Pull Request #4911 · scala-js/scala-js · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 2 commits into from
Oct 18, 2023

Conversation

gzm0
Copy link
Contributor
@gzm0 gzm0 commented Oct 15, 2023

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:

  • SJSGen#genCallHelper
  • VarGen#globalVar
  • VarGen#globalVarIdent
  • VarGen#genericIdent

By defining the relevant strings statically (including the leading $), we avoid the duplication.

Discovered while working on #4906.

@gzm0
Copy link
Contributor Author
gzm0 commented Oct 15, 2023

Based on #4909 due to merge conflicts.

Dispatchers are the only place where we pass a dynamically computed
string to the VarGen subsystem.
@gzm0 gzm0 requested a review from sjrd October 16, 2023 07:02
@gzm0 gzm0 marked this pull request as ready for review October 16, 2023 07:02
Copy link
Member
@sjrd sjrd left a 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
Copy link
Member

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?

Suggested change
private[emitter] final class VarFld private (val str: String) extends AnyVal
private[emitter] final class VarField private (val str: String) extends AnyVal

Copy link
Contributor Author

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 = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def mk(str: String): VarFld = {
private def mk(str: String): VarFld = {

/** Scala class constructors (<init>). */
final val ct = mk("$ct")

/** Scala class initializers (<cinit>). */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** Scala class initializers (<cinit>). */
/** Scala class initializers (<clinit>). */

/** Scala module accessor. */
final val m = mk("$m")

/** Var / let to store Scala module instnance.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** Var / let to store Scala module instnance.
/** Var / let to store Scala module instance.

/** Class data. */
final val d = mk("$d")

/** inInstanceOf functions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** inInstanceOf functions.
/** isInstanceOf functions.


final val moduleDefault = mk("$moduleDefault")

// Arithemtic Call Helpers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Arithemtic Call Helpers
// Arithmetic Call Helpers

@gzm0
Copy link
Contributor Author
gzm0 commented Oct 17, 2023

I have addressed all the comments. I have also added private[emitter] to object VarField.

@gzm0 gzm0 requested a review from sjrd October 17, 2023 18:03
@sjrd sjrd merged commit b8fb2f2 into scala-js:main Oct 18, 2023
@gzm0 gzm0 deleted the static-fields branch October 22, 2023 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0