4 ms·
> If one is interested in doing this optimally, it should be better to compile python code to javascript directly. Well no, this is not possible, because pytho
by Raphael_Amiard 16y ago
> If one is interested in doing this optimally, it should be better to compile python code to javascript directly.
Well no, this is not possible, because python and javascript have very different semantics, notably regarding numeric types. You would have to enclose every python numeral in an object, and that in itself would already cripple the performance quite a bit. It would probably be less than the emscripten approach, but not by that much of a margin.
I started doing a python to lua compiler, and did hit that wall very fast.
Pyjamas python to javascript compiler is basically a toy regarding compliance to python spec. Every number is treated as a float, which means any numeric python library/function may not work correctly in pyjamas.
That's not the only difference in semantics between python and javascript. Just the most performance expensive.
- wkornewald 16y agoNote that pyjs has several compilation options, one of which wraps numbers to distinguish between float and int. However, stuff like correct delegation with multiple inheritance might never work because js can only have one delegate. Currently one of the big problems in practice is that attribute access doesn't behave like getattr, which makes working with @property inconsistent. Also, __call__ doesn't work. Lots of minor details. At least they are checked in the unit tests, in case someone wants to help.
- Raphael_Amiard 16y agoHey, thanks for the precision, i didn't know you could box numbers in pyjs, i wonder how i missed that when i read the source. What is the typical performance hit from doing that ?
- wkornewald 16y agoI really don't remember the exact numbers, anymore. A few times slower. The slowdown certainly is significant enough for number-crunching code, but end-users wouldn't notice the difference for simple calculations. I haven't yet played with per-module compilation flags, but it would be possible to compile performance-critical modules with a higher optimization level. Such a solution might require a little wrapper to convert between the data types, depending on the chosen compilation options, but it's the same when talking to raw JS code.