Thursday, December 23, 2010

Is the Web Ready for Compiled Code?

CPython compiled to JavaScript is now reasonably fast on Firefox 4 and Chrome. Startup takes a few seconds, but it could be done in a web worker, so as not to stall a loading page. Executing code afterwards is far slower than native CPython, but already fast enough to be useful for some things, and getting faster all the time. (There are other limitations, like importing of modules, but I'm mainly focusing on speed for now.) So, from the perspective of those two browsers, we might be able to use Python on the web.

However, for it to make sense in general, it needs to work well on all or almost all browsers people use. So, what's the situation with other browsers?
  • The Python demo tends to run very slowly in older browsers, that don't have a modern JavaScript engine. But, those people will upgrade eventually, so this will be solved (except perhaps for a minority using IE6...).
  • Currently Python will not run on Opera, due to a bug in their JS engine. They have been notified of the problem. As Opera has a quite fast JS engine, I am hopeful that compiled code will work there at some point.
  • IE9 has a fast JS engine as well, but I don't have a Windows machine to test on. Has anyone tried to run the Python demo there? Update: Issue 22.
  • Safari has had a fast JS engine for a while (these days perhaps not as fast as the other open source ones, given recent speedups in Firefox and Chrome, but still quite good). As in the previous point, I lack a machine to test on - has anyone tried there? Update: Works in Safari and even iPads.

4 comments:

  1. Doesn't work here on IE9 PP 7:

    SCRIPT438: Object doesn't support this property or method
    BespinEmbedded.js, line 59 character 494
    SCRIPT438: Object doesn't support this property or method
    python.js, line 15 character 44

    ReplyDelete
  2. Thanks for trying it on IE9!

    Looks like this might be fixable, I filed issue 22 to continue the investigation,

    http://code.google.com/p/emscripten/issues/detail?id=22

    ReplyDelete
  3. CPython works on Safari 5.0.3. Some bugs in some of the examples on the Python SimplePrograms page though (excluding the ones using imports, of course):

    http://wiki.python.org/moin/SimplePrograms

    Haven't checked to see if those problems exist on other browsers yet though. Good test samples to run.

    ReplyDelete
  4. @Eric: Thanks! I'm checking out those bugs.

    ReplyDelete