-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to aggressively inline all literals and consts
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)
- Loading branch information
Showing
11 changed files
with
505 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
float inl1() | ||
{ | ||
return 126.; | ||
} | ||
float inl2(float x) | ||
{ | ||
if(x>246913578.) | ||
return 100.; | ||
if(x>123456789.) | ||
return 101.; | ||
return 102.; | ||
} | ||
float inl3() | ||
{ | ||
return.75*(2.*acos(-1.)); | ||
} | ||
float inl4() | ||
{ | ||
return.75*(2.*acos(-1.)); | ||
} | ||
float inl5() | ||
{ | ||
return 579.; | ||
} | ||
float inl6() | ||
{ | ||
return 2.*(2.*acos(-1.)); | ||
} | ||
void notevil(float x) | ||
{ | ||
x=42.; | ||
} | ||
float inl7() | ||
{ | ||
return notevil(101.),101.; | ||
} | ||
int inl8(ivec3 x) | ||
{ | ||
int i=1; | ||
x[i]+=1; | ||
return x[i]+i; | ||
} | ||
float noinl1() | ||
{ | ||
float f=42.; | ||
f=101.; | ||
return f; | ||
} | ||
float noinl2() | ||
{ | ||
float f=42.; | ||
f++; | ||
return f; | ||
} | ||
float noinl3() | ||
{ | ||
float f=42.; | ||
if(acos(-1.)<3.) | ||
f=101.; | ||
return f; | ||
} | ||
float noinl4() | ||
{ | ||
float f=42.; | ||
for(f=0.;false;) | ||
; | ||
return f; | ||
} | ||
float noinl5() | ||
{ | ||
float f=42.; | ||
for(;false;f++) | ||
; | ||
return f; | ||
} | ||
float noinl6(float x) | ||
{ | ||
float f=x+1.; | ||
x=100.; | ||
return f+2.; | ||
} | ||
float noinl7(const float x) | ||
{ | ||
return x+1.2; | ||
} | ||
float quux=1.; | ||
float noinl8() | ||
{ | ||
return quux+2.; | ||
} | ||
float noinl9(float x) | ||
{ | ||
float bar=x+1.; | ||
x=100.; | ||
return bar+2.; | ||
} | ||
void evil(inout float x) | ||
{ | ||
x=42.; | ||
} | ||
float noinl10() | ||
{ | ||
float f=101.; | ||
evil(f); | ||
return f; | ||
} | ||
int noinl11(ivec3 x) | ||
{ | ||
int i=1; | ||
x[i++]+=1; | ||
return x[i]+i; | ||
} |
Oops, something went wrong.