Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ryan Kelly: PyPy.js: What? How? Why?

Ryan Kelly: PyPy.js: What? How? Why?

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Ryan Kelly:
PyPy.js: What? How? Why?
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
@ Kiwi PyCon 2014 - Sunday, 14 Sep 2014 - Track 1
http://kiwi.pycon.org/

**Audience level**

Intermediate

**Description**

PyPy.js is an experiment in building a fast and compliant in-browser python interpreter, by compiling PyPy into javascript and retargeting its JIT to emit asmjs code at runtime. This talk will demonstrate the combination of technologies that make such a thing possible, the results achieved so far, and the challenges that still remain when taking python onto javascript's home turf.

**Abstract**

PyPy.js is an experiment in building a fast, compliant, in-browser python interpreter. By compiling the PyPy interpreter into javascript, and retargeting its JIT compiler to emit asmjs code at runtime, it is possible to run python code in the browser at speeds competitive with a native python environment. This talk will demonstrate the combination of technologies that make such a thing possible, the results that have been achieved so far, and the challenges that still remain when trying to take python onto javascript's home turf.

We'll cover: an overview of PyPy and why it's a good fit for this type of project; an introduction to asmjs and the rise of javascript as a compile target; what it looks like when you smoosh these two technologies together; a comparison with other approaches such as brython; and some concrete suggestions for how the result might be useful in practice.

**YouTube**

https://www.youtube.com/watch?v=pt-e-X_q-dk

New Zealand Python User Group

September 14, 2014
Tweet

More Decks by New Zealand Python User Group

Other Decks in Programming

Transcript

  1. Andreas Gal, Mozilla CTO: "For Mozilla, anything that the Web

    can’t do, or anything that the Web is not faster and better at than native technologies, is a bug." https://bugzilla.mozilla.org/
  2. PyPy.js is ... Not the First Pyjamas PyJS Skulpt Brython

    PythonJS RapydScript Pystachio Pyjaco ...?
  3. PyPy.js is ... In­Browser v a r v m =

    n e w P y P y J S ( ) ; v m . r e a d y . t h e n ( f u n c t i o n ( ) { . . . } ) v m . s e t ( " x " , 1 2 ) . t h e n ( . . . ) v m . e v a l ( " x = x + 1 " ) . t h e n ( . . . ) v m . g e t ( " x " ) . t h e n ( . . . )
  4. PyPy.js is ... "An experiment in building a fast, compliant,

    in­browser python environment" But...
  5. PyPy: A Python interpreter, written in "RPython" A toolchain for

    translating RPython to C A JIT­Compiler­Generator
  6. Emscripten: An LLVM backend that generates JavaScript A simulated POSIX

    environment, in JavaScript Originally for porting games to the web
  7. f u n c t i o n S q

    r t M o d u l e ( s t d l i b , f o r e i g n , h e a p ) { " u s e a s m " ; v a r s q r t = s t d l i b . M a t h . s q r t ; v a r H E A P F 6 4 = n e w s t d l i b . F l o a t 6 4 A r r a y ( h e a p ) ; f u n c t i o n s q r t _ p t r ( a d d r ) { a d d r = a d d r | 0 ; v a r x = 0 . 0 ; x = + H E A P F 6 4 [ a d d r > > 3 ] ; H E A P F 6 4 [ a d d r > > 3 ] = + s q r t ( x ) ; } r e t u r n { s q r t _ p t r : s q r t _ p t r } ; }
  8. PyPy.js: How? PyPy.py PyPy.c PyPy.js mycode.js mycode.x86 mycode.py PyPy.x86 rpython

    js jit emcc pypy jit js jit cpu micro-ops prediction pipelining ...
  9. PyPy.js: Why? < s c r i p t t

    y p e = " t e x t / p y t h o n " > p r i n t ( " b u h - b y e j a v a s c r i p t ! " ) < / s c r i p t >