Skip to content
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

Add option to aggressively inline all literals and consts #136

Merged
merged 1 commit into from
May 10, 2022

Conversation

jwatzman
Copy link
Contributor

@jwatzman jwatzman commented May 9, 2022

This new inlining option does two things:

  • Inlines any variable which looks like a literal constant
    (hasInitDeps is false) and which does not appear in an lvalue
    position
  • Inlines any variable marked as const whatsoever.

This can increase program size, if a large literal is inlined over and
over. However, the idea is exactly why the Google Closure Compiler also
always inlines constants: a (the?) major use-case of this minifier is
for demoscene shaders, which are almost certainly going to be put
through compression later anyway -- so what matters is the size after
compression, not the actual output size. And reducing the redudancy that
this inlining creates can be done by the compressor in way fewer bytes
than declaring a new variable in the program text.

https://github.com/google/closure-compiler/wiki/FAQ#closure-compiler-inlined-all-my-strings-which-made-my-code-size-bigger-why-did-it-do-that

This option isn't the default; we likely want to do more testing to see
if it actually works out that way in practise (and to make sure the
output doesn't break things!) However, when I tested it on the two
largest shaders in tests/real (the_real_party... and lunaquatic),
it not only reduced gzip'd size but also raw output size too. So it may
just be a win all-around anyway?

  • the_real_party...: 17708 -> 17699 (gzipped 5181 -> 5173)
  • lunaquatic: 7356 -> 7347 (gzipped 2745 -> 2739)

Copy link
Owner

@laurentlb laurentlb left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

src/rewriter.fs Outdated Show resolved Hide resolved
src/rewriter.fs Outdated Show resolved Hide resolved
This new inlining option does two things:
- Inlines any variable which looks like a literal constant
  (`hasInitDeps` is false) and which does not appear in an lvalue
  position
- Inlines any variable marked as `const` whatsoever.

This can increase program size, if a large literal is inlined over and
over. However, the idea is exactly why the Google Closure Compiler also
always inlines constants: a (the?) major use-case of this minifier is
for demoscene shaders, which are almost certainly going to be put
through compression later anyway -- so what matters is the size after
compression, not the actual output size. And reducing the redudancy that
this inlining creates can be done by the compressor in way fewer bytes
than declaring a new variable in the program text.

https://github.com/google/closure-compiler/wiki/FAQ#closure-compiler-inlined-all-my-strings-which-made-my-code-size-bigger-why-did-it-do-that

This option isn't the default; we likely want to do more testing to see
if it actually works out that way in practise (and to make sure the
output doesn't break things!) However, when I tested it on the two
largest shaders in `tests/real` (`the_real_party...` and `lunaquatic`),
it not only reduced gzip'd size but also raw output size too. So it may
just be a win all-around anyway?

- `the_real_party...`: 17708 -> 17699 (gzipped 5181 -> 5173)
- `lunaquatic`: 7356 -> 7347 (gzipped 2745 -> 2739)
@laurentlb laurentlb merged commit cb2a710 into laurentlb:master May 10, 2022
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