It's really awesome to see how far this has come. I believe we at Repl.it were the first to try something like this in production. We emscriptined CPython to JavaScript and contributed quite a bit to the project in the process (including the initial virtual filesystem implementation).
I deployed this at scale at Codecademy were millions of users were using it to learn Python but hit a lot of problems with it. For one, if you're in a 3rd world country then the bundle size is a non-starter (this is potentially solved with WASM being a binary format). Even if you managed to download the bundle lots of old computers would run out of memory trying to parse the JS (again probably solved by the binary AST format of WASM). Because of this and a few other issues (the dev experience of emscripten was really hard) we had to move away to running code on remote containers.
Now that I'm back working on Repl.it full time I'm excited to play again with the tech and see what we can do with it this time around.
I just wanted to say how much I love Repl.it and use it all the time. I use it as a testing scratchpad mostly but I know it's much powerful than that. I appreciate its simplicity. Thanks for a great product!
I believe emscripten provides a virtual filesystem interface. Since it's essentially translating/running c it's either hooking through glibc or the syscall interfaces.
The speed is surprisingly reasonable. Testing with a simple loop, I get about 1.3-1.4 million loops per second in python3, 2 million loops per second in python2, 14.5 million loops in pypy, and 0.61 million loops in the browser.
My code basically calls int(time.time()) until its value changes, doing i+=1 for every time it did not change (n=10 for every platform (python2/3/pypy/browser)). My browser is Firefox 61, full code here: https://hastebin.com/turenofise.py
Fetching time in the browser isn't accurate because a lot of trackers exploit timing in order to fingerprint users. A lot of browsers now purposefully reduce the precision of the clock. See:
I wonder if the time.time is the slow part there? Maybe worth doing a busy look for say 5 million iterations, timing that then doing the calculation for loops per second.
I'd expect a much larger difference in tasks that are pure Python (loading a CSV is done primarily through the csv module, i.e. all the hot loops are in C).
I'd love there to be a client-side webapp development system using Python with feature and output parity to JavaScript. If it was a product, I would buy it.
Yeah weird. I would expect Python2 to be dying off more by now. Wonder if we're headed to an environment where there's essentially 2 separate languages as Python 3 continues to change and grow?
This is pretty old, and hasn't seen an update in over a year. I never understand why links links this get posted with no discussion to start it off with.
Also, wouldn't this be better implemented with WASM?
I tried to do a little something with Emscripten and WebAssembly, but I stopped on the sockets implementation. It relies on WebSockets. I wonder how well we could emulate real sockets using WebRTC to make WebAssembly apps more sophisticated.
Is there an up-to-date/maintained comparison of python-in-the-browser systems? As well as this, there's brython and skulpt, and it would be nice to be able to compare various implemented features, quirks and speed.
Really amazing. I use python every day at work, and most of the crucial libraries have tight inner loops written in C or Cython. I wonder what the web assembly future holds for those languages, and inter-language FFI.
There's no python standard, but my guess is that-- since this is based on the same source code that native PyPy is, with a different compiler backend -- they are making the claim based on the fact that native PyPy is widely considered to be similar enough to CPython for many workloads. Thus -- assuming the correctness of the RPython -> JavaScript transformation (which they have not proven, and would be a monumental task) -- you should expect this version to work like the native PyPy.
this is pretty neat! I was wondering, are there any projects to transpile python to js, but targeting the server side? It would be interesting to port a flask application, for example, to run on node and benefit from the jit, or maybe use express and call flask through its wsgi interface.
[+] [-] amasad|7 years ago|reply
https://github.com/replit-archive/empythoned
I deployed this at scale at Codecademy were millions of users were using it to learn Python but hit a lot of problems with it. For one, if you're in a 3rd world country then the bundle size is a non-starter (this is potentially solved with WASM being a binary format). Even if you managed to download the bundle lots of old computers would run out of memory trying to parse the JS (again probably solved by the binary AST format of WASM). Because of this and a few other issues (the dev experience of emscripten was really hard) we had to move away to running code on remote containers.
Now that I'm back working on Repl.it full time I'm excited to play again with the tech and see what we can do with it this time around.
[+] [-] flanbiscuit|7 years ago|reply
[+] [-] jumasheff|7 years ago|reply
[+] [-] hathawsh|7 years ago|reply
[+] [-] mattigames|7 years ago|reply
[+] [-] kjeetgill|7 years ago|reply
[+] [-] matmann2001|7 years ago|reply
[+] [-] unknown|7 years ago|reply
[deleted]
[+] [-] lucb1e|7 years ago|reply
My code basically calls int(time.time()) until its value changes, doing i+=1 for every time it did not change (n=10 for every platform (python2/3/pypy/browser)). My browser is Firefox 61, full code here: https://hastebin.com/turenofise.py
[+] [-] shuzchen|7 years ago|reply
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
https://johnresig.com/blog/accuracy-of-javascript-time/
[+] [-] alexchamberlain|7 years ago|reply
[+] [-] tim333|7 years ago|reply
[+] [-] philipov|7 years ago|reply
[+] [-] jwilk|7 years ago|reply
Here's the code:
[+] [-] asmosoinio|7 years ago|reply
[+] [-] veganjay|7 years ago|reply
It is used by a class taught on Coursera (Introduction to Interactive Programming in Python)
From what I can see:
- PyPy.js benefit: runs faster
- codeskulptor benefit: can use GUI components
[+] [-] adamwiggins|7 years ago|reply
To my surprise it was faster than Jupyter / CPython for some tasks (e.g. loading and parsing large CSVs).
[+] [-] dunpeal|7 years ago|reply
http://speed.pypy.org/
I'd expect a much larger difference in tasks that are pure Python (loading a CSV is done primarily through the csv module, i.e. all the hot loops are in C).
[+] [-] benatkin|7 years ago|reply
Naturally, I changed the first code block to this:
[+] [-] bmays|7 years ago|reply
[+] [-] VectorLock|7 years ago|reply
[+] [-] tony-allan|7 years ago|reply
[+] [-] rtkwe|7 years ago|reply
[+] [-] jchw|7 years ago|reply
[+] [-] wietze|7 years ago|reply
[+] [-] cybersol|7 years ago|reply
[+] [-] cecilpl2|7 years ago|reply
[+] [-] duhi88|7 years ago|reply
Also, wouldn't this be better implemented with WASM?
[+] [-] stev0lution|7 years ago|reply
[+] [-] whalesalad|7 years ago|reply
[+] [-] toyg|7 years ago|reply
[+] [-] anarchy8|7 years ago|reply
So pretty much like every Python project then. What's happening to the Python community?
[+] [-] costrouc|7 years ago|reply
[+] [-] aylmao|7 years ago|reply
What I gather is that it's compiling CPython to WASM and ships it along with some other utilities. It looks pretty cool.
[+] [-] ipsun4|7 years ago|reply
[+] [-] jokoon|7 years ago|reply
[+] [-] klhugo|7 years ago|reply
[+] [-] askvictor|7 years ago|reply
[+] [-] imh|7 years ago|reply
[+] [-] slezyr|7 years ago|reply
[+] [-] cutler|7 years ago|reply
So this is a subset of Python or something like that?
[+] [-] Nicksil|7 years ago|reply
Edit: Just checked the site and see it uses PyPy which states -- on their site -- the python version is 3.5.3
[+] [-] nichochar|7 years ago|reply
[+] [-] tathougies|7 years ago|reply
[+] [-] parabx|7 years ago|reply
[+] [-] icebraining|7 years ago|reply
[+] [-] Skunkleton|7 years ago|reply
[+] [-] nautilus12|7 years ago|reply
[+] [-] antoineMoPa|7 years ago|reply
[+] [-] ealhad|7 years ago|reply