Author: Armin Rigo <ar...@tunes.org> Branch: extradoc Changeset: r5598:8b46adc6da63 Date: 2016-01-30 22:46 +0100 http://bitbucket.org/pypy/extradoc/changeset/8b46adc6da63/
Log: updated slides, check in the html version diff --git a/talk/fosdem2016/slides b/talk/fosdem2016/slides --- a/talk/fosdem2016/slides +++ b/talk/fosdem2016/slides @@ -324,7 +324,7 @@ - it does not expose any part of the CPython C API - - everything is done with a different, minimal API on the ``ffi`` object + - everything is done with a minimal API on the ``ffi`` object which is closer to C - ``ffi.cast()``, ``ffi.new()``, etc. diff --git a/talk/fosdem2016/slides.html b/talk/fosdem2016/slides.html new file mode 100644 --- /dev/null +++ b/talk/fosdem2016/slides.html @@ -0,0 +1,728 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta name="generator" content="Docutils 0.12: http://docutils.sourceforge.net/" /> +<meta name="version" content="S5 1.1" /> +<title>CFFI and PyPy</title> +<style type="text/css"> + +/* +:Author: David Goodger (good...@python.org) +:Id: $Id: html4css1.css 7614 2013-02-21 15:55:51Z milde $ +:Copyright: This stylesheet has been placed in the public domain. + +Default cascading style sheet for the HTML output of Docutils. + +See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to +customize this style sheet. +*/ + +/* used to remove borders from tables and images */ +.borderless, table.borderless td, table.borderless th { + border: 0 } + +table.borderless td, table.borderless th { + /* Override padding for "table.docutils td" with "! important". + The right padding separates the table cells. */ + padding: 0 0.5em 0 0 ! important } + +.first { + /* Override more specific margin styles with "! important". */ + margin-top: 0 ! important } + +.last, .with-subtitle { + margin-bottom: 0 ! important } + +.hidden { + display: none } + +a.toc-backref { + text-decoration: none ; + color: black } + +blockquote.epigraph { + margin: 2em 5em ; } + +dl.docutils dd { + margin-bottom: 0.5em } + +object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] { + overflow: hidden; +} + +/* Uncomment (and remove this text!) to get bold-faced definition list terms +dl.docutils dt { + font-weight: bold } +*/ + +div.abstract { + margin: 2em 5em } + +div.abstract p.topic-title { + font-weight: bold ; + text-align: center } + +div.admonition, div.attention, div.caution, div.danger, div.error, +div.hint, div.important, div.note, div.tip, div.warning { + margin: 2em ; + border: medium outset ; + padding: 1em } + +div.admonition p.admonition-title, div.hint p.admonition-title, +div.important p.admonition-title, div.note p.admonition-title, +div.tip p.admonition-title { + font-weight: bold ; + font-family: sans-serif } + +div.attention p.admonition-title, div.caution p.admonition-title, +div.danger p.admonition-title, div.error p.admonition-title, +div.warning p.admonition-title, .code .error { + color: red ; + font-weight: bold ; + font-family: sans-serif } + +/* Uncomment (and remove this text!) to get reduced vertical space in + compound paragraphs. +div.compound .compound-first, div.compound .compound-middle { + margin-bottom: 0.5em } + +div.compound .compound-last, div.compound .compound-middle { + margin-top: 0.5em } +*/ + +div.dedication { + margin: 2em 5em ; + text-align: center ; + font-style: italic } + +div.dedication p.topic-title { + font-weight: bold ; + font-style: normal } + +div.figure { + margin-left: 2em ; + margin-right: 2em } + +div.footer, div.header { + clear: both; + font-size: smaller } + +div.line-block { + display: block ; + margin-top: 1em ; + margin-bottom: 1em } + +div.line-block div.line-block { + margin-top: 0 ; + margin-bottom: 0 ; + margin-left: 1.5em } + +div.sidebar { + margin: 0 0 0.5em 1em ; + border: medium outset ; + padding: 1em ; + background-color: #ffffee ; + width: 40% ; + float: right ; + clear: right } + +div.sidebar p.rubric { + font-family: sans-serif ; + font-size: medium } + +div.system-messages { + margin: 5em } + +div.system-messages h1 { + color: red } + +div.system-message { + border: medium outset ; + padding: 1em } + +div.system-message p.system-message-title { + color: red ; + font-weight: bold } + +div.topic { + margin: 2em } + +h1.section-subtitle, h2.section-subtitle, h3.section-subtitle, +h4.section-subtitle, h5.section-subtitle, h6.section-subtitle { + margin-top: 0.4em } + +h1.title { + text-align: center } + +h2.subtitle { + text-align: center } + +hr.docutils { + width: 75% } + +img.align-left, .figure.align-left, object.align-left { + clear: left ; + float: left ; + margin-right: 1em } + +img.align-right, .figure.align-right, object.align-right { + clear: right ; + float: right ; + margin-left: 1em } + +img.align-center, .figure.align-center, object.align-center { + display: block; + margin-left: auto; + margin-right: auto; +} + +.align-left { + text-align: left } + +.align-center { + clear: both ; + text-align: center } + +.align-right { + text-align: right } + +/* reset inner alignment in figures */ +div.align-right { + text-align: inherit } + +/* div.align-center * { */ +/* text-align: left } */ + +ol.simple, ul.simple { + margin-bottom: 1em } + +ol.arabic { + list-style: decimal } + +ol.loweralpha { + list-style: lower-alpha } + +ol.upperalpha { + list-style: upper-alpha } + +ol.lowerroman { + list-style: lower-roman } + +ol.upperroman { + list-style: upper-roman } + +p.attribution { + text-align: right ; + margin-left: 50% } + +p.caption { + font-style: italic } + +p.credits { + font-style: italic ; + font-size: smaller } + +p.label { + white-space: nowrap } + +p.rubric { + font-weight: bold ; + font-size: larger ; + color: maroon ; + text-align: center } + +p.sidebar-title { + font-family: sans-serif ; + font-weight: bold ; + font-size: larger } + +p.sidebar-subtitle { + font-family: sans-serif ; + font-weight: bold } + +p.topic-title { + font-weight: bold } + +pre.address { + margin-bottom: 0 ; + margin-top: 0 ; + font: inherit } + +pre.literal-block, pre.doctest-block, pre.math, pre.code { + margin-left: 2em ; + margin-right: 2em } + +pre.code .ln { color: grey; } /* line numbers */ +pre.code, code { background-color: #eeeeee } +pre.code .comment, code .comment { color: #5C6576 } +pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } +pre.code .literal.string, code .literal.string { color: #0C5404 } +pre.code .name.builtin, code .name.builtin { color: #352B84 } +pre.code .deleted, code .deleted { background-color: #DEB0A1} +pre.code .inserted, code .inserted { background-color: #A3D289} + +span.classifier { + font-family: sans-serif ; + font-style: oblique } + +span.classifier-delimiter { + font-family: sans-serif ; + font-weight: bold } + +span.interpreted { + font-family: sans-serif } + +span.option { + white-space: nowrap } + +span.pre { + white-space: pre } + +span.problematic { + color: red } + +span.section-subtitle { + /* font-size relative to parent (h1..h6 element) */ + font-size: 80% } + +table.citation { + border-left: solid 1px gray; + margin-left: 1px } + +table.docinfo { + margin: 2em 4em } + +table.docutils { + margin-top: 0.5em ; + margin-bottom: 0.5em } + +table.footnote { + border-left: solid 1px black; + margin-left: 1px } + +table.docutils td, table.docutils th, +table.docinfo td, table.docinfo th { + padding-left: 0.5em ; + padding-right: 0.5em ; + vertical-align: top } + +table.docutils th.field-name, table.docinfo th.docinfo-name { + font-weight: bold ; + text-align: left ; + white-space: nowrap ; + padding-left: 0 } + +/* "booktabs" style (no vertical lines) */ +table.docutils.booktabs { + border: 0px; + border-top: 2px solid; + border-bottom: 2px solid; + border-collapse: collapse; +} +table.docutils.booktabs * { + border: 0px; +} +table.docutils.booktabs th { + border-bottom: thin solid; + text-align: left; +} + +h1 tt.docutils, h2 tt.docutils, h3 tt.docutils, +h4 tt.docutils, h5 tt.docutils, h6 tt.docutils { + font-size: 100% } + +ul.auto-toc { + list-style-type: none } + +</style> +<!-- configuration parameters --> +<meta name="defaultView" content="slideshow" /> +<meta name="controlVis" content="hidden" /> +<!-- style sheet links --> +<script src="ui/default/slides.js" type="text/javascript"></script> +<link rel="stylesheet" href="ui/default/slides.css" + type="text/css" media="projection" id="slideProj" /> +<link rel="stylesheet" href="ui/default/outline.css" + type="text/css" media="screen" id="outlineStyle" /> +<link rel="stylesheet" href="ui/default/print.css" + type="text/css" media="print" id="slidePrint" /> +<link rel="stylesheet" href="ui/default/opera.css" + type="text/css" media="projection" id="operaFix" /> + +<style type="text/css"> +#currentSlide {display: none;} +</style> +</head> +<body> +<div class="layout"> +<div id="controls"></div> +<div id="currentSlide"></div> +<div id="header"> + +</div> +<div id="footer"> +<h1>CFFI and PyPy</h1> + +</div> +</div> +<div class="presentation"> +<div class="slide" id="slide0"> +<h1 class="title">CFFI and PyPy</h1> + + +</div> +<div class="slide" id="cffi"> +<h1>CFFI</h1> +<ul class="simple"> +<li>successful project according to PyPI</li> +<li>3.4 million downloads last month</li> +<li>total 19.2 millions, 27th place on <cite>pypi-ranking.info</cite><ul> +<li>Django is 28th</li> +</ul> +</li> +<li>some high-visibility projects have switched to it (Cryptography)</li> +</ul> +</div> +<div class="slide" id="pypy"> +<h1>PyPy</h1> +<ul class="simple"> +<li>harder to say, but probably not so successful</li> +<li>more later</li> +</ul> +</div> +<div class="slide" id="id1"> +<h1>CFFI</h1> +</div> +<div class="slide" id="id2"> +<h1>CFFI</h1> +<ul class="simple"> +<li>call C from Python</li> +<li>CFFI = C Foreign Function Interface</li> +<li>shares ideas from Cython, ctypes, and LuaJIT's FFI</li> +</ul> +</div> +<div class="slide" id="cffi-demo"> +<h1>CFFI demo</h1> +<pre class="literal-block"> +$ man getpwuid + +SYNOPSIS + #include <sys/types.h> + #include <pwd.h> + + struct passwd *getpwnam(const char *name); +</pre> +</div> +<div class="slide" id="id3"> +<h1>CFFI demo</h1> +<pre class="literal-block"> +. +. +. +The passwd structure is defined in <pwd.h> as follows: + + struct passwd { + char *pw_name; /* username */ + char *pw_passwd; /* user password */ + uid_t pw_uid; /* user ID */ +. +. +. +</pre> +</div> +<div class="slide" id="id4"> +<h1>CFFI demo</h1> +<pre class="literal-block"> +from cffi import FFI +ffi = cffi.FFI() + +ffi.cdef(""" + typedef int... uid_t; + struct passwd { + uid_t pw_uid; + ...; + }; + struct passwd *getpwnam(const char *name); +""") +</pre> +</div> +<div class="slide" id="id5"> +<h1>CFFI demo</h1> +<pre class="literal-block"> +ffi.set_source("_pwuid_cffi", """ + #include <sys/types.h> + #include <pwd.h> +""") + +ffi.compile() +</pre> +<p>------- ^^ put that in pwuid_build.py</p> +</div> +<div class="slide" id="id6"> +<h1>CFFI demo</h1> +<pre class="literal-block"> +python pwuid_build.py +</pre> +<p>creates <tt class="docutils literal">_pwuid_cffi.so</tt></p> +</div> +<div class="slide" id="id7"> +<h1>CFFI demo</h1> +<pre class="literal-block"> +from _pwuid_cffi import lib + +print lib.getpwnam("arigo").pw_uid +</pre> +</div> +<div class="slide" id="id8"> +<h1>CFFI demo</h1> +<pre class="literal-block"> +from _pwuid_cffi import ffi, lib +</pre> +<ul> +<li><p class="first"><tt class="docutils literal">lib</tt> gives access to all functions from the cdef</p> +</li> +<li><p class="first"><tt class="docutils literal">ffi</tt> gives access to a few general helpers, e.g.</p> +<blockquote> +<ul class="simple"> +<li><tt class="docutils literal"><span class="pre">ffi.cast("float",</span> 42)</tt></li> +<li><tt class="docutils literal">p = <span class="pre">ffi.new("struct</span> passwd *")</tt></li> +<li><tt class="docutils literal">p = <span class="pre">ffi.new("char[10]");</span> p[0] = 'X'; s = lib.getpwnam(p)</tt></li> +<li><tt class="docutils literal">p = ffi.new_handle(random_obj); <span class="pre">...;</span> random_obj = ffi.from_handle(p)</tt></li> +</ul> +</blockquote> +</li> +</ul> +</div> +<div class="slide" id="id9"> +<h1>CFFI</h1> +<ul class="simple"> +<li>supports more or less the whole C</li> +<li>there is more than my short explanation suggests</li> +<li>read the docs: <a class="reference external" href="http://cffi.readthedocs.org/">http://cffi.readthedocs.org/</a></li> +</ul> +</div> +<div class="slide" id="id10"> +<h1>PyPy</h1> +</div> +<div class="slide" id="id11"> +<h1>PyPy</h1> +<ul class="simple"> +<li>a Python interpreter</li> +<li>different from the standard, which is CPython</li> +<li>main goal of PyPy: speed</li> +</ul> +</div> +<div class="slide" id="id12"> +<h1>PyPy</h1> +<pre class="literal-block"> +$ pypy + +Python 2.7.10 (5f8302b8bf9f, Nov 18 2015, 10:46:46) +[PyPy 4.0.1 with GCC 4.8.4] on linux2 +Type "help", "copyright", "credits" or "license" for more information. +>>>> 2+3 +5 +>>>> +</pre> +</div> +<div class="slide" id="id13"> +<h1>PyPy</h1> +<ul class="simple"> +<li>run <tt class="docutils literal">pypy my_program.py</tt></li> +<li>starts working like an interpreter</li> +<li>then a Just-in-Time Compiler kicks in</li> +<li>generate and execute machine code from the Python program</li> +<li>good or great speed-ups for the majority of long-running code</li> +</ul> +</div> +<div class="slide" id="id14"> +<h1>PyPy</h1> +<ul class="simple"> +<li>different techniques than CPython also for "garbage collection"</li> +<li>works very well (arguably better than CPython's reference counting)</li> +</ul> +</div> +<div class="slide" id="pypy-garbage-collection"> +<h1>PyPy: Garbage Collection</h1> +<ul class="simple"> +<li>"<strong>moving,</strong> generational, incremental GC"</li> +<li>objects don't have reference counters</li> +<li>allocated in a "nursery"</li> +<li>when nursery full, find surviving nursery objects and move them out</li> +<li>usually work on nursery objects only (fast), but rarely also perform +a full GC</li> +</ul> +</div> +<div class="slide" id="pypy-c-extensions"> +<h1>PyPy: C extensions</h1> +<ul class="simple"> +<li>PyPy works great for running Python</li> +<li>less great when there are CPython C extension modules involved</li> +</ul> +</div> +<div class="slide" id="id15"> +<h1>PyPy: C extensions</h1> +<ul class="simple"> +<li>not directly possible: we have moving, non-reference-counted objects, +and the C code expects non-moving, reference-counted objects</li> +</ul> +</div> +<div class="slide" id="id16"> +<h1>PyPy: C extensions</h1> +<ul class="simple"> +<li>PyPy has still some support for them, called its <tt class="docutils literal">cpyext</tt> module</li> +<li>similar to IronPython's Ironclad</li> +<li>emulate all objects for C extensions with a shadow, non-movable, +reference-counted object</li> +</ul> +</div> +<div class="slide" id="id17"> +<h1>PyPy: C extensions</h1> +<ul class="simple"> +<li><tt class="docutils literal">cpyext</tt> is slow</li> +<li><tt class="docutils literal">cpyext</tt> is actually <em>really, really</em> slow<ul> +<li>but we're working on making it <em>only</em> slow</li> +</ul> +</li> +</ul> +</div> +<div class="slide" id="id18"> +<h1>PyPy: C extensions</h1> +<ul class="simple"> +<li><tt class="docutils literal">cpyext</tt> will "often" work, but there are a some high-profile C +extension modules that are not supported so far</li> +<li>notably, <tt class="docutils literal">numpy</tt></li> +<li>(it is future work)</li> +</ul> +</div> +<div class="slide" id="pypy-ad"> +<h1>PyPy: ad</h1> +<ul class="simple"> +<li>but, hey, if you need performance out of Python and don't rely +critically on C extension modules, then give PyPy a try<ul> +<li>typical area where it works well: web services</li> +</ul> +</li> +</ul> +</div> +<div class="slide" id="cpython-c-api-the-problem"> +<h1>CPython C API: the problem</h1> +<ul class="simple"> +<li>CPython comes with a C API</li> +<li>very large number of functions</li> +<li>assumes objects don't move</li> +<li>assumes a "reference counting" model</li> +</ul> +</div> +<div class="slide" id="cpython-c-api"> +<h1>CPython C API</h1> +<ul class="simple"> +<li>actually, the API is some large subset of the functions inside +CPython itself</li> +</ul> +</div> +<div class="slide" id="id19"> +<h1>CPython C API</h1> +<ul class="simple"> +<li>easy to use from C</li> +<li>historically, part of the success of Python</li> +</ul> +</div> +<div class="slide" id="id20"> +<h1>CPython C API</h1> +<ul class="simple"> +<li>further successful tools build on top of that API:<ul> +<li>SWIG</li> +<li>Cython</li> +<li>and other binding generators</li> +<li>now CFFI</li> +</ul> +</li> +</ul> +</div> +<div class="slide" id="id21"> +<h1>CFFI</h1> +<ul class="simple"> +<li>but CFFI is a bit different<ul> +<li>it does not expose any part of the CPython C API</li> +<li>everything is done with a minimal API on the <tt class="docutils literal">ffi</tt> object +which is closer to C<ul> +<li><tt class="docutils literal">ffi.cast()</tt>, <tt class="docutils literal">ffi.new()</tt>, etc.</li> +</ul> +</li> +<li>that means it can be directly ported</li> +</ul> +</li> +</ul> +</div> +<div class="slide" id="id22"> +<h1>CFFI and PyPy</h1> +<ul class="simple"> +<li>we have a PyPy version of CFFI</li> +<li>the demos I have given above work equally well on CPython or on PyPy</li> +<li>(supporting PyPy was part of the core motivation behind CFFI)</li> +</ul> +</div> +<div class="slide" id="cffi-performance"> +<h1>CFFI: performance</h1> +<ul class="simple"> +<li>in PyPy, JIT compiler speeds up calls, so it's very fast</li> +<li>in CPython, it doesn't occur, but it is still reasonable when +compared with alternatives</li> +<li>main issue is that we write more code in Python with CFFI, +which makes it slower on CPython---but not really on PyPy</li> +</ul> +</div> +<div class="slide" id="cffi-summary"> +<h1>CFFI: summary</h1> +<ul class="simple"> +<li>call C from Python</li> +<li>works natively on CPython and on PyPy<ul> +<li>and easy to port to other Python implementations</li> +</ul> +</li> +<li>supports CPython 2.6, 2.7, 3.2 to 3.5, and +is integrated with PyPy</li> +</ul> +</div> +<div class="slide" id="id23"> +<h1>CFFI</h1> +<ul class="simple"> +<li>independent on the particular details of the Python implementation<ul> +<li>using CFFI, you call C functions and manipulate C-pointer-like +objects directly from Python</li> +<li>you do in Python all logic involving Python objects</li> +<li>there are no (official) ways around this API to call the CPython C +API, and none are needed</li> +</ul> +</li> +</ul> +</div> +<div class="slide" id="id24"> +<h1>CFFI</h1> +<ul class="simple"> +<li>two reasons to switch to it <tt class="docutils literal"><span class="pre">:-)</span></tt><ul> +<li>easy and cool</li> +<li>better supported on non-CPython implementations</li> +</ul> +</li> +</ul> +</div> +<div class="slide" id="cffi-latest-news"> +<h1>CFFI: latest news</h1> +<ul class="simple"> +<li>support for "embedding" Python inside some other non-Python program<ul> +<li>now you really never need the CPython C API any more</li> +</ul> +</li> +</ul> +</div> +<div class="slide" id="id25"> +<h1>CFFI</h1> +<p><a class="reference external" href="http://cffi.readthedocs.org/">http://cffi.readthedocs.org/</a></p> +</div> +</div> +</body> +</html> _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit