Live data from Hacker News

Closure Compiler in JavaScript

developers.googleblog.com

31–40 of 115 posts

Re: Closure Compiler in JavaScript

#32

> How does this work? > > This isn't a rewrite of Closure in JavaScript. Instead, we compile > the Java source to JS to run under Node, or even inside a plain old > browser. Every post or resource you see about Closure Compiler will > also apply to this version. Pretty wild.

I'm really interested in how they did that. Do they have an internal Emscripten equivalent for Java bytecode? Or would it be more like a source code conversion compiler a la Nim or Haxe?

Re: Closure Compiler in JavaScript

#33
post #30
post #19

Earlier quoted context omitted.

The advanced compilation mode does some pretty powerful dead code removal and minification [1]. I guess that is available from plugins in Babel as well but Google has been using it for Gmail, Google.com etc, so it's quite battle tested. [1]: https://developers.google.com/closure/compiler/docs/api-tuto...

Dead code removal relies heavily on writing JS in a style that allows for static analysis. Dynamic requires, heavy usage of closures, knowledge of external/global variables are all things that prevent a lot of commonjs code from being removed. https://developers.google.com/closure/compiler/docs/limitati... has more information if you're interested in the assumptions that the compiler makes. Interestingly, we're final…

Works very nicely as an LLVM of sort for alt.js languages though, as they can generate JS in such a way that it matches clojure's constraints and requirements.

Re: Closure Compiler in JavaScript

#34
post #32

> How does this work? > > This isn't a rewrite of Closure in JavaScript. Instead, we compile > the Java source to JS to run under Node, or even inside a plain old > browser. Every post or resource you see about Closure Compiler will > also apply to this version. Pretty wild.

I'm really interested in how they did that. Do they have an internal Emscripten equivalent for Java bytecode? Or would it be more like a source code conversion compiler a la Nim or Haxe?

Far less glamorous and way more old school, it's the later case - GWT can compile Java to JavaScript.

Re: Closure Compiler in JavaScript

#35
post #32

> How does this work? > > This isn't a rewrite of Closure in JavaScript. Instead, we compile > the Java source to JS to run under Node, or even inside a plain old > browser. Every post or resource you see about Closure Compiler will > also apply to this version. Pretty wild.

I'm really interested in how they did that. Do they have an internal Emscripten equivalent for Java bytecode? Or would it be more like a source code conversion compiler a la Nim or Haxe?

GWT has a Java->Javascript compiler.

Re: Closure Compiler in JavaScript

#36
performance is significantly worse for the simple example, anecdotally feels maybe 300%-400% slower.

not sure if it's just bootup time or actual compilation passes, hopefully the former and does not explode exponentially (or even linearly) with code size.

Re: Closure Compiler in JavaScript

#38
post #2

Does anyone know what this means for clojurescript?

Nothing. Zero benefits here for typical usage of ClojureScript. Potentially interesting for 3rd party bootstrap efforts like Planck, Lumo, etc.

True, but it helps fix the TTFX metric -- "Time to First XML" ;-) -- Derek Slager made a case for this in his talk at the Conj:

"ClojureScript for Skeptics" https://youtu.be/gsffg5xxFQI?t=20m9s

The remaining bit of Java is like "a little piece of kelp that's stuck to the hull, and even though it's little, you don't want anything stuck to the hull" (http://www.tv-quotes.com/shows/the-west-wing/quote_14096.htm...).

TTFX 1: http://clojurescript.org/guides/quick-start

Re: Closure Compiler in JavaScript

#40
post #32

Earlier quoted context omitted.

I'm really interested in how they did that. Do they have an internal Emscripten equivalent for Java bytecode? Or would it be more like a source code conversion compiler a la Nim or Haxe?

Far less glamorous and way more old school, it's the later case - GWT can compile Java to JavaScript.

Wait, how is that a thing? I'm a pure JS developer (for now) but I don't understand how something framed on desktop OSs could compile to JS, a browser language. Does it compile to Node maybe? Which version of JS?

EDIT: I'm googling now to learn more but I'm not asking to challenge anybody, I'm asking because probably you guys know more than me and I wanna know how this works.

Post reply on HN