Live data from Hacker News

PyPy.js: Python in the web browser

pypyjs.org

91–100 of 129 posts

Re: PyPy.js: Python in the web browser

#91
post #76

Earlier quoted context omitted.

I believe this feature was introduced in Python 3.6. This implementation may be 3.6 Edit: Just checked the site and see it uses PyPy which states -- on their site -- the python version is 3.5.3

I can't do: a, *b = range(3) which should be 3.5 i think.

Other comments in this thread point to the implementation likely being Python 2.x.

Re: PyPy.js: Python in the web browser

#92
post #83

Would it be sane to use this to run Python modules in node.js?

If the Python module was large and complex, it does something that would be incredibly difficult to replicate in nodejs either given the current ecosystem or costs of a rewrite, is not available in Rust/C/C++ that could be WASM'd (not mentioning others here due to large WASM overhead), you accept the large binary sizes of these things (i.e. you're not embedding the Python interpreter/runtime and putting on npm), and you're willing to put a node-friendly layer on top that makes the lower level calls...then it might be sane. But I'd consider modernizing to an updated emscripten that does WASM, see if you can avoid some emscripten runtime (i.e. WASM standalone compilation).

For all other cases, stay in Node or use a lib from a language more suited to WASM compilation. Now, if it's an option between this and a native Node module, that depends on your opinion of Node FFI and native Node modules.

Re: PyPy.js: Python in the web browser

#94
post #52

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, ful…

This pastebin requires JS...

Here's the code:

  import time
  a=-1
  j = 0
  i=0
  while j 

Re: PyPy.js: Python in the web browser

#95
post #78
post #52

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, ful…

Though trying to add the numbers for 1 to a million in a loop javascript was about 10 - 20 times faster when I tried it.

You would use sum(range()) in a Python though. Remember that many things you do manually in JS have a better, automatic and faster way in the stlib.

Besides, if calculations are important, you would use numpy.

Re: PyPy.js: Python in the web browser

#96
post #52

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, ful…

Which version of python 3 did you test with? I expected 3.6+ to be faster than python 2.7

Python 3.6.6 from Debian Buster in a VirtualBox VM on a Windows 10 host. Testing with 3.7.0, the result is no different. Python 3.5 is no longer available in the repositories to test whether that is indeed slower.

Re: PyPy.js: Python in the web browser

#97
post #52

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, ful…

Which version of python 3 did you test with? I expected 3.6+ to be faster than python 2.7

int in python2 is a more simple structure (fixed precision for non-long integers) than int of python3 (arbitrary precision)

Re: PyPy.js: Python in the web browser

#98
post #52

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, ful…

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'm sure it is a thousand times slower than i++, but it should be the same code on each platform.

But you made me think: indeed, the underlying call could be slower from JS whereas from pypy/python{2,3} it's fast (or vice versa). So I just tested a version where it checks how long ten million iterations take (n=3). Code here: https://hastebin.com/uyuhecabek.py

    browser/pypy   5.25 seconds
    python 3.6.6   2.16 seconds
    python 3.7.0   2.08 seconds
    python 2.7.15  1.42 seconds
    pypy   6.0.0   0.01 seconds
Since there is no syscall to be made, pypy can do this in compiled code and is blazingly fast (I bet C/assembly isn't much faster there), and the rest seems comparable to the previous estimate: the browser version is 2.25× slower compared to python3 (now 2.43×) and 3.33× slower compared to python2 (now 3.70×).

Re: PyPy.js: Python in the web browser

#99
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).

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.

Re: PyPy.js: Python in the web browser

#100
post #78
post #52

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, ful…

Though trying to add the numbers for 1 to a million in a loop javascript was about 10 - 20 times faster when I tried it.

[deleted]
Post reply on HN