<<
This is puzzling. I have just run some tests and top level data structures
do appear to be eliminated.
For example: (def x {:a "XXXXXXXX" :b 2})
I was NOT able to find the string "XXXXXXXX" in the JavaScript compiled
under ":optimizations :advanced".
Can you provide any more clarity on this rule?
>>
I used this online closure instance:
http://closure-compiler.appspot.com/home
and selected "Advanced" optimization
then entered this:
a = {name: "test"} // a is top level i.e. window.a = {name: "test"}
function abc() { // abc() is also top level i.e. window.abc = function
abc() { return true}
return true
}
Output:
a={name:"test"};
// where did abc() go? never called so it's eliminated, but what about a?
If you were to enter:
var a = {name: "test"}
function abc() {
return true
}
you'll get 0 bytes in output
now if you enter:
window.a = {name: "test"}
window.abc = function abc() {
return true
}
you get:
window.a={name:"test"};window.b=function(){return!0};
so then one (or only?) way an unused function is eliminated while an unused
variable is not is if they somehow are converted to JS as:
a = {name: "test"}
function abc() {
return true
}
On Tue, Mar 10, 2015 at 10:08 PM, Gregg Ramsey <[email protected]>
wrote:
> This is puzzling. I have just run some tests and top level data structures
> do appear to be eliminated.
>
> For example: (def x {:a "XXXXXXXX" :b 2})
>
> I was NOT able to find the string "XXXXXXXX" in the JavaScript compiled
> under ":optimizations :advanced".
>
> Can you provide any more clarity on this rule?
>
>
> On Wednesday, 11 March 2015 13:49:52 UTC+11, David Nolen wrote:
> > If you want your library to be dead code elimination friendly don't use
> top level data structures.
> >
> >
> > It's a very simple rule.
> >
> >
> > David
> >
> >
> > On Tue, Mar 10, 2015 at 8:19 PM, Mike Thompson <[email protected]>
> wrote:
> > This issue from David Nolen, caught my eye:
> >
> > https://github.com/andrewmcveigh/cljs-time/issues/21
> >
> >
> >
> > Feels like there is important information there, but I just don't know
> enough to interpret what's said. Can anyone help?
> >
> >
> >
> > If I have this:
> >
> >
> >
> > (def x {:a 1 :b 2})
> >
> >
> >
> > David is saying that x can't be dead-code-eliminated. Correct?
> >
> >
> >
> > If so, the solution he talks about is?
> >
> >
> >
> > ;; Replacing PersistentHashMaps with functions? Can't be right. I think
> I'm being too literal here
> >
> > (def x ((fn [] {:a 1 :b2})))
> >
> >
> >
> > ;; more likely this?
> >
> >
> >
> > (defn x
> >
> > []
> >
> > {:a 1 :b 2})
> >
> >
> >
> > Ie. you must now "call" x to get the map.
> >
> >
> >
> > If this solution is the right one, doesn't that mean we would be
> inefficiently constructing the (potentially large) hashmap inside x on each
> call.
> >
> >
> >
> > --
> >
> > Mike
> >
> >
> >
> >
> >
> > --
> >
> > Note that posts from new members are moderated - please be patient with
> your first post.
> >
> > ---
> >
> > You received this message because you are subscribed to the Google
> Groups "ClojureScript" group.
> >
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected].
> >
> > To post to this group, send email to [email protected].
> >
> > Visit this group at http://groups.google.com/group/clojurescript.
>
> --
> Note that posts from new members are moderated - please be patient with
> your first post.
> ---
> You received this message because you are subscribed to the Google Groups
> "ClojureScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/clojurescript.
>
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.