-
Notifications
You must be signed in to change notification settings - Fork 396
More minification. #4931
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
More minification. #4931
Conversation
bceb896
to
1be1bbe
Compare
0d5e313
to
2394217
Compare
bfd8ab5
to
054b708
Compare
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.
Nice! I'm wondering if the last commit should go into its own PR, but given how many comments we'll have here already, it might make sense to keep the discussion history.
linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/SJSGen.scala
Outdated
Show resolved
Hide resolved
linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/CoreJSLib.scala
Outdated
Show resolved
Hide resolved
linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/CoreJSLib.scala
Show resolved
Hide resolved
linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/Emitter.scala
Outdated
Show resolved
Hide resolved
linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/ClassEmitter.scala
Outdated
Show resolved
Hide resolved
linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/OptimizerCore.scala
Outdated
Show resolved
Hide resolved
linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/OptimizerCore.scala
Show resolved
Hide resolved
linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/OptimizerCore.scala
Show resolved
Hide resolved
linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/OptimizerCore.scala
Outdated
Show resolved
Hide resolved
linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/OptimizerCore.scala
Show resolved
Hide resolved
On an unrelated note: IMO given how many total hours went into this vs GCC, this is quite the achievement :) |
Addressed comments of all the commits except the last one. |
OK it should be all addressed, now. |
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.
A couple of things I saw on second read only. Sorry for the extra iteration. (also some typos, but they are really minor).
linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/SJSGen.scala
Outdated
Show resolved
Hide resolved
linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/ClassEmitter.scala
Outdated
Show resolved
Hide resolved
linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/ClassEmitter.scala
Outdated
Show resolved
Hide resolved
linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/OptimizerCore.scala
Show resolved
Hide resolved
linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/OptimizerCore.scala
Show resolved
Hide resolved
linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/OptimizerCore.scala
Show resolved
Hide resolved
When minifying, a susprisingly large amount of bytes in the resulting .js file are caused by the `prototype`s in: C.prototype.f = function(...) { ... }; C.prototype.g = function(...) { ... }; We can get rid of them by assigning `C.prototype` once to a temporary variable, then reusing it many times: $p = C.prototype; $p.f = function(...) { ... }; $p.f = function(...) { ... }; This commit implements that strategy when the `minify` config is on.
* Merge `isInterface` and `isJSType` as a single parameter `kind` that is an integer. * Use the first element of `ancestors` instead of independently passing the `internalName` (this is safe because ES 2015 guarantees the order of `getOwnPropertyNames`). * Really remove the `parentData` parameter when reachability analysis says it is not accessed.
This removes the largest source of uncompressible and non-removable occurrences of `$classData` identifiers. It does increase the size of the GCC output in the `LibrarySizeTest`, but it does not translate to the `reversi` checksizes, so it is probably a small codebase artifact.
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.
Just one nit about the new comment.
linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/OptimizerCore.scala
Show resolved
Hide resolved
During the optimizer, when emitting a `VarDef(x, ..., rhs)`, we try to inline it if it has been used exactly once. In order to do that, we look at the `body` in which it will be available, and replace its only occurrence if it occurs in the first evaluation context following only pure subexpressions. See the long comment in the code for more details.
Based on #4945.
All together, this brings a 17% code size reduction in a Vite full build, compared to what we get at the end of #4945. We're still 14% bigger than what we get with GCC, but that's a lot more acceptable than the status quo.