This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

This is a Python hack to let you specify functions as “inline” in much the same way you’d do in C. You save the cost of a function call by inlining the code of the function right at the call site. Of course, being Python, the inlining is done at runtime.

WARNING: Don’t use this in any real code. Seriously. It’s just a fun hack.

Now then, suppose you have some code like this:

def calculate(x):
    return 3*x*x - 2*x + (1/x)

def aggregate(items):
    total = 0
    for item in items:
        total += calculate(item)
    return total

This code pays the overhead of a function call for every item in the collection. You can get substantial speedups by inlining the calculate function like so:

def aggregate(items):
    total = 0
    for x in items:
        total += 3*x*x - 2*x + (1/x)
    return total

But now you’re paying the costs in terms of code quality and re-use. To get the best of both worlds simply declare that the calculate function should be inlined:

from atinline import inline

@inline
def calculate(x):
    return 3*x*x - 2*x + (1/x)

def aggregate(items):
    total = 0
    for item in items:
        total += calculate(item)
    return total

Now the first time the aggregate() function runs, it will detect that the calculate() function should be inlined, make the necessary bytecode hacks to do so, then continue on its way. Any subsequent calls to aggregate() will avoid the overhead of many function calls.

Currently only plain calls of top-level functions are supported; things won’t work correctly if you try to inline methods, functions looked up in a dict, or other stuff like this. It also doesn’t work with keyword arguments. These limitations might go away in future.

The heavy-lifting of bytecode regeneration is done by the fantastic “byteplay” module, which is atinline’s only dependency.

Release History

Release History

0.1.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
atinline-0.1.1.tar.gz (7.0 kB) Copy SHA256 Checksum SHA256 Source Apr 16, 2011

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting