8000 Intern unscoped global field name strings by gzm0 · Pull Request #4910 · scala-js/scala-js · GitHub
[go: up one dir, main page]

Skip to content

Intern unscoped global field name strings #4910

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

Closed
wants to merge 1 commit into from

Conversation

gzm0
Copy link
Contributor
@gzm0 gzm0 commented Oct 8, 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

A more invasive (but efficient) alternative would be to move the prefix to the call sites. As a result, no runtime interning would have to be performed as the strings would end up being part ot the static constant pool.

Discovered while working on #4906.

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

A more invasive (but efficient) alternative would be to move the
prefix to the call sites. As a result, no runtime interning would have
to be performed as the strings would end up being part ot the static
constant pool.

Discovered while working on scala-js#4906.
@gzm0 gzm0 requested a review from sjrd October 8, 2023 10:00
@gzm0
Copy link
Contributor Author
gzm0 commented Oct 8, 2023

@sjrd WYDT? I've been toying with the idea of having all the fields in VarGen (maybe even in an AnyVal). This would give us some more compile time safety and a point of documentation (what the fields actually contain).

@sjrd
Copy link
Member
sjrd commented Oct 8, 2023

Common wisdom goes against the use of the global intern mechanism. Not sure whether this is justified. But it does feel wasteful to construct at run-time "$" + field, only to intern it right away, when we in fact have a known finite set of such fields.

I've been toying with the idea of having all the fields in VarGen (maybe even in an AnyVal). This would give us some more compile time safety and a point of documentation (what the fields actually contain).

This seems like a much better alternative, indeed.

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

Closing in favor of #4911.

@gzm0 gzm0 closed this Oct 15, 2023
@gzm0 gzm0 deleted the intern-fields branch February 3, 2024 13:34
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