Live data from Hacker News

PyPy.js: A fast, compliant Python implementation for the web

pypyjs.org

61–70 of 144 posts

Re: PyPy.js: A fast, compliant Python implementation for the web

#61

Earlier quoted context omitted.

Just playing around: import js c = js.globals.document.createElement("canvas") js.globals.document.body.appendChild(c) ctx = c.getContext("2d") ctx.fillRect(10, 10, 10, 10) Edit: Here is a simple animation: import js import math import time c = js.globals.document.createElement("canvas") js.globals.document.body.appendChild(c) ctx = c.getContext("2d") def render(): ctx.clearRect(0, 0, c.width, c.height) t = time.time…

Sadly, if I paste that in, I get: >>> import js ... c = js.globals.document.createElement("canvas") ... debug: OperationError: debug: operror-type: SyntaxError debug: operror-value: ('EOL while scanning string literal', ('c callback', 1, 12, "r = c.push('import js\n", 0)) debug: OperationError: debug: operror-type: KeyError debug: operror-value: 'r' And then the input window hangs. Strangely enough, if I type it in i…

I think the only way around it is to paste each line separately. It seems to be caused by newline characters in the wrong place

Re: PyPy.js: A fast, compliant Python implementation for the web

#62
post #11

This is glorious. From https://github.com/rfk/pypyjs/blob/master/CONTRIBUTING.rst : > We have the following major components in the PyPy repo: >> An "emscripten" build platform definition, which teaches pypy's rpython toolchain how to compile things with emscripten: ./deps/pypy/rpython/translator/platform/emscripten_platform/. >> An rpython JIT backend that emits asmjs at runtime: ./deps/pypy/rpython/jit/backend/asmj…

Since PyPy compiles RPython to C, couldn't one write a web app in RPython, compile it to C, then to JS (with asm.js) and enjoy a quick page load and smaller file size? By the way, is RPython a nice language to program in?

> is RPython a nice language to program in?

Not really, if only for the insane compile times. The PyPy authors also heavily discourage using it except for interpreters.

Re: PyPy.js: A fast, compliant Python implementation for the web

#63

Earlier quoted context omitted.

Since PyPy compiles RPython to C, couldn't one write a web app in RPython, compile it to C, then to JS (with asm.js) and enjoy a quick page load and smaller file size? By the way, is RPython a nice language to program in?

The differences are described here: https://rpython.readthedocs.org/en/latest/rpython.html

Thanks but to be honest, I'm not proficient in Python, so it's hard to guess if those restrictions would hurt, although they seem fairly small. I was more asking for personnal opinions and projects using it. I wasn't able to quickly find any, it even seems pretty much nobody writes RPython code or maybe people call it Python code so googling is hard.

Re: PyPy.js: A fast, compliant Python implementation for the web

#64
post #56

Please humour my lack of knowledge: is there much difference between something like this and Opal[0]? [0] - http://opalrb.org

PyPy.js is not a transpiler, it is a JITted interpreter. This has correctness advantages since the major work is upfront, and potential throughput advantages, but is results in huge upfront download and warmup costs.

Re: PyPy.js: A fast, compliant Python implementation for the web

#65

Unfortunately, this is of little use to me. Why? Well, with my Swedish keyboard layout, some alt-combinations are crucial (mainly square brackets, []). And these keypresses do not seem to work.

You can try `vm.eval` from the JS console.

Re: PyPy.js: A fast, compliant Python implementation for the web

#67
post #5

Besides the big download size, it does several things very "right": Full Python data model, access to the full javascript model (albeit slowly currently). Also PyPy is the right choice as the basis for this (as opposed to CPython) because its ecosystem is generally more "pure" Python than CPython's. C Extensions would only get in the way.

it's systematically translating the PyPy interpreter to the Javascript, so it has to get semantics right. However I'm not sure if the drawbacks can be addressed in the current JS model, notably: very slow warmup, huge download size (that's primarily PyPy fault though), the lack of good JS access.

> However I'm not sure if the drawbacks can be addressed in the current JS model, notably: very slow warmup, huge download size

Only for the first time loading it.

It would be great if some big organization (looks at Google) hosts the "standard" version of the file, much like jquery, so that it would be cached and ready to be used on the local machine most of the time.

Re: PyPy.js: A fast, compliant Python implementation for the web

#69

Earlier quoted context omitted.

The differences are described here: https://rpython.readthedocs.org/en/latest/rpython.html

Thanks but to be honest, I'm not proficient in Python, so it's hard to guess if those restrictions would hurt, although they seem fairly small. I was more asking for personnal opinions and projects using it. I wasn't able to quickly find any, it even seems pretty much nobody writes RPython code or maybe people call it Python code so googling is hard.

I don't know of any real projects outside of interpreters that use it. It has downsides (long compile times come to mind) and I'm not sure how well you can utilize the strengths (like the JIT) for non-interpreters.

EDIT: Writing it is more restricted than normal Python, so you have to think about what you do (especially type hints, to make sure it gets what type your variables are) and the long feedback cycles due to compile time are annoying, but still very comfortable. And for building interpreters, the more or less "free" JIT is magic :)

Re: PyPy.js: A fast, compliant Python implementation for the web

#70
post #9

I watched the presentation in Pycon 2015[1], and I really liked how honest/aware they are about the challenges and tradeoffs (so far, the performance it's pretty bad compared to javascript, and the download size is still an issue). At the end is answered why python can't be directly included in Firefox or other browsers(the presenter/main developer works for Mozilla) [1] https://www.youtube.com/watch?v=PiBfOFqDIAI

> At the end is answered why python can't be directly included in Firefox or other browsers(the presenter/main developer works for Mozilla)

Direct link to answer: https://youtu.be/PiBfOFqDIAI?t=1611

Post reply on HN