andrewducker: (Default)
andrewducker ([personal profile] andrewducker) wrote2010-11-11 12:55 pm

Coding in web browsers

[livejournal.com profile] robhu has a good point over here.

At the moment we write Javascript in web pages, which is then compiled down by the various JIT methods that Firefox/IE/Webkit use to make it super fast.

Seeing as what's run clearly isn't the actual JS itself, but bytecode, why not have a standardised bytecode that all browsers would support, which would then mean you could write your code in any language you liked, providing there was a compiler to convert it to the standardised bytecode?

At the moment Google uses GWT to convert Java into Javascript that then gets converted into the running code, (And MS used to have something similar) wouldn't it be handy if the intermediate step wasn't necessary?
drplokta: (Default)

[personal profile] drplokta 2010-11-11 01:31 pm (UTC)(link)
It's the big 4, I'm afraid. Safari and Chrome have not dissimilar usage figures (especially when you include all the people using Safari on iPhones, iPod Touches and iPads).

But my point is that it's not possible to have the same bytecode run natively in multiple browsers, or indeed in the same browser on different OS platforms. It will have to be run through a VM that translates the bytecode into actual native code in any case, so why not just call the Javascript interpreter the VM?
drplokta: (Default)

[personal profile] drplokta 2010-11-11 01:39 pm (UTC)(link)
As I said upthread, Javascript probably isn't expressive and powerful enough, but I don't see how your new thing is going to avoid the standard-defining/implementing processes that have bollixed Javascript up. If you do have some new way to avoid the bollixisation of web standards, then simply apply this process to fixing Javascript.

[identity profile] strawberryfrog.livejournal.com 2010-11-11 03:12 pm (UTC)(link)
Javascript can't be fixed without breaking existing javascript code. It was like that from the start.

[identity profile] skington.livejournal.com 2010-11-11 02:32 pm (UTC)(link)
Don't Safari and Chrome have different JS engines? Irrespective of whether they share a rendering engine.

[identity profile] call-waiting.livejournal.com 2010-11-11 01:31 pm (UTC)(link)
In what way is it suboptimal? There's a slight time penalty in the translation from the higher-level language than bytecode, and there's a bit of a semantic gap between java and javascript, but it isn't necessarily terribly inefficient. If the javascript emitted is low-level enough, all the potential optimisation in the original source code can be exposed and there's almost no work for the host JIT to do.

Similarly, it's possible to write C code that's low-level enough that it's virtually impossible to do better by writing in assembly.
drplokta: (Default)

[personal profile] drplokta 2010-11-11 01:34 pm (UTC)(link)
Actually, I believe that C code tends to be faster than assembly these days, because the compiler is better than you are at ordering opcodes to take best advantage of modern CPU architectures and allow simultaneous execution of instructions in nominally single-threaded code while minimising waits.

[identity profile] call-waiting.livejournal.com 2010-11-11 01:37 pm (UTC)(link)
In general, absolutely. Certainly on a modern superscalar CPU. But in the DSP space, assembly programmers have the edge when they have sufficient time to spend on an inner loop (and they're allowed to make assumptions that compilers aren't)

[identity profile] jouni osmala (from livejournal.com) 2010-11-11 02:37 pm (UTC)(link)
In 90's the assembly programming book simply stated, that if you hand translate your C code to assembler you loose. But if you solve the problem directly in assembler you could get ~6X performance improvement.
Another thing to consider is that assembler really requires LOTS of knowledge to actually be better than writing same in C.
Assembly acts as a leverage of your knowledge base, by giving you direct control over constraints that you do not have access to in C.
The amount of knowledge required for assembly to win over C is couple thousand pages worth of knowledge that isn't much use outside assembler programming how many programmers have read it?