10000 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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Intern unscoped global field name strings
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.
  • Loading branch information
gzm0 committed Oct 8, 2023
commit 21d00d9317388e28b562e966906bde4e2a594972
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private[emitter] final class VarGen(jsGen: JSGen, nameGen: NameGen,
origName: OriginalName = NoOriginalName)(
implicit pos: Position): Ident = {
val name =
if (subField == "") "$" + field
if (subField == "") ("$" + field).intern()
else "$" + field + "_" + subField

Ident(avoidClashWithGlobalRef(name), origName)
Expand Down
0