DOM access would allow a Javascript compiler?

24 views
Skip to first unread message

Ian

unread,
Sep 29, 2009, 5:47:42 AM9/29/09
to Native Client Discuss
I have absolutely no idea what the planned future is for this project
(so forgive me if this has already been announced or discussed
elsewhere.) I very much doubt that I am the first person to think of
this - but it seems to me that if NaCl was enhanced so that a NEXE
could do everything with a browser that you can currently do in
Javascript (e.g. access the DOM etc.) then a logical next step might
be to create a compiler that compiled an entire web page (or perhaps
just the Javascript part) into a NEXE file. My understanding of the
Google Chrome V8 project is that it is essentially a Javascript
compiler already - producing native machine code which is then
executed (but not saved?) Perhaps it would not be very much work to
modify V8 to create a standalone compiler which generated a NEXE as
output when pointed at an HTML or JS file. GWT could then be enhanced
to compile straight from Java to NEXE (in addition to JS, since not
everyone will have NaCl installed to run the NEXE).

Of course the $64K question is - could this be made to perform better
than using Javascript with V8 in the current arrangement? Perhaps DOM
access between NaCl and browser might require inter-process-
communication overhead, which in DOM-heavy applications might
completely outweigh any performance gain from having pre-compiled code
in a NEXE file? (Although there might well be other possible benefits
such as total code obfuscation, reduced download time, improved
startup time etc. etc....)

Is this a technical possibility, or am I off on a complete tangent?
Ian

Brad Chen

unread,
Oct 1, 2009, 12:14:32 AM10/1/09
to native-cli...@googlegroups.com
There's a lot of interesting  ideas in here and I won't try to respond to all of them. I did want to point out a few relevant facts:
  • We have provided an NPAPI interface to NaCl modules in the past, and it will be coming back soon. This provides fairly generally access to browser/javascript state, and we're working with the community on some revisions to address performance and portability issues.
  • We've done some exploratory work into using WebIDL to generate a DOM interface on top of NPAPI. Once our NPAPI support has stabilized again we should be able to get back to this idea.
  • As browsers are currently constructed, JavaScript does have some inherent advantages over a NaCl language implementation. For example parts of the DOM are commonly implemented in JavaScript. If NaCl is successful, some of these advantages may go away over time, provided they actually matter to real applications.
  • JavaScript is a tricky language, being extremely dynamic. Implementations like V8 are already astonishingly good. I think you'd have to make some deep changes in the language to support compilation. Even then I'm not sure how much faster it could be.
Brad

Mike Hearn

unread,
Oct 20, 2009, 3:58:58 PM10/20/09
to Native Client Discuss
Something else to bear in mind is that compiled native code tends to
be a lot larger than the equivalent obfuscated JavaScript. You may
gain in runtime performance (theoretically) but you may lose in
transfer time.

Ian

unread,
Oct 20, 2009, 7:26:42 PM10/20/09
to Native Client Discuss
Hopefully the browser would cache the NEXE so it only has to download
it on the first visit, so that the transfer overhead is only incurred
once. (And obviously incurred again for software updates - when the
NEXE timestamp changes.)

Being able to go from a GWT app to NEXE file still seems like it might
be a desirable thing to do - although it doesn't sound like a
Javascript compiler is the appropriate way to go about that. I wonder
if someone in future might adapt the GNU Java compiler (gcj) to
compile Java to NEXE. Mind you, that probably introduces a multitude
of other issues to be dealt with.

My thinking is that there seems to be a considerable effort going into
the development of NaCl and I have a strong feeling that is intended
for much more than just C and C++ apps. Given the strategic importance
of GWT at Google (e.g. Google Wave), I sense that GWT will perhaps fit
into the NaCl picture at some stage. But I guess I will just have to
be patient and see how it all pans out.

Ian

unread,
Nov 10, 2009, 9:37:43 PM11/10/09
to Native Client Discuss
Maybe just forget Javascript (and Java) altogether and code in Go
instead! Looks like there has already been some preliminary work done
with Go to integrate with NaCl. (See http://golang.org/pkg/exp/nacl)
Reply all
Reply to author
Forward
0 new messages