Live data from Hacker News

PyPy.js: Python in the web browser

pypyjs.org

101–110 of 129 posts

Re: PyPy.js: Python in the web browser

#101
post #67
post #58

Earlier quoted context omitted.

This is Javascript, not real Python. If you're so afraid that this is dangerous, why do you post malicious code? And if you're so clever to post that code, why don't you try similar code to see if it really has access to your files? import os os.listdir('/') The answer, by the way, is no.

> If you're so afraid that this is dangerous, why do you post malicious code? That's not malicious code... it removes files from a sandbox... you can refresh the page and see for yourself. > And if you're so clever to post that code There's no need to be rude... there's an honest question and lack of understanding in my post - educate me, don't talk down to me. > why don't you try similar code to see if it really has…

Thanks for the elaborate response, now I much better understand what you're trying to say.

This is different from the examples you mention: there is no external software that creates the sandbox (whereas with Java and Flash you had to install those as plugins). It's really just Javascript as it is built into the browser. Any vulnerability in this "sandbox" is a vulnerability in the browser, not some 3rd party plugin.

Put differently, this pypy emulation is no different from the Javascript API that was in your browser already. This isn't a new plugin, just using Javascript to emulate Python through the Pypy interpreter.

Re: PyPy.js: Python in the web browser

#102
post #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 Pyth…

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!

Re: PyPy.js: Python in the web browser

#103

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.

You should give Nim a try. It's a Python-like language which can be compiled to C and JavaScript. There is even a SPA framework[1] for it already and the NimForum[2] is written in it.

1 - https://github.com/pragmagic/karax

2 - http://forum.nim-lang.org/

Re: PyPy.js: Python in the web browser

#104
post #98

Earlier quoted context omitted.

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 pytho…

I'm surprised it's that different; in the optimum case, it feels like a several layers of JITing interpreter should get to the same performance in the end. Might not be enough to trigger it I guess.

Re: PyPy.js: Python in the web browser

#105
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…

There's some pypy.js vs cpython benchmarks at http://arewepythonyet.com/ - those look very good as well.

Re: PyPy.js: Python in the web browser

#106
post #78

Earlier quoted context omitted.

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.

Ah yes. sum(range()) in Python vs for(i=1...) in js was much closer, about 20% quicker in javascript.

Re: PyPy.js: Python in the web browser

#108
post #50

Earlier quoted context omitted.

Yes, but PyPy is usually compiled to machine code (and emits machine code), not to JS.

True, but the asm.js is then compiled to machine code by the browser's JS JIT. I'd expect some overhead from sandboxing etc., but it should be fairly close to native speed.

It's not "overhead from sandboxing" that's a problem, it's the fact that translating from bytecode to bytecode to bytecode will cause it to lose some ... succinctness at each step, giving the final machine code generator a harder time coming up with efficient code for it.

Re: PyPy.js: Python in the web browser

#109

Earlier quoted context omitted.

It's stable and mature? If you've been writing JavaScript your whole career you might not know what that looks like.

Such a snarky response, but I can't deny it. I see a JS package that hasn't been updated in a year and I expect that it won't even build with my environment because webpack evolution. I see a python package that hasn't been updated in a year and it doesn't faze me. Not a whole lot that can break in terms of building and integration with my python project.

Perspective is everything. Now and again I use C libraries that haven't been updated in 15 years. Why? There isn't a need. Everything builds perfectly, and some of those libraries are still the go-to solutions in my field.

Re: PyPy.js: Python in the web browser

#110
post #98

Earlier quoted context omitted.

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 pytho…

I'm surprised it's that different; in the optimum case, it feels like a several layers of JITing interpreter should get to the same performance in the end. Might not be enough to trigger it I guess.

I can't see the code because I'm on mobile, but if the JIT is function based and you're only calling the benchmarked function once it may not have it optimized for your first call. It certainly can't replace the instructions mid-loop.

Edit: SO answer explaining the PyPy JIT: https://stackoverflow.com/questions/37377787/what-kind-of-ji...

Post reply on HN