bytecode optimisation using staticness assertions.
Project description
promise: bytecode optimisation using staticness assertions.
This is a module for applying some simple optimisations to function bytecode.
By promising that a function doesn't do certain things at run-time, it's
possible to apply optimisations that are not legal in the general case.
As a simple example, it's possible to promise that a function doesn't modify
(or care if anyone else modifies) any builtin functions by decorating it thus:
@promise.constant(__builtins__)
def function():
...
Such a promise will allow the builtins to be stored as direct object references
in the function bytecode, avoiding name lookups during function execution.
As another example, it's possible to promise that a function is pure; i.e. that
it's a simple algorithm for mapping input values to an output value:
@promise.pure()
def calculate(a,b):
return 2*a*a + 3*b + 7
If a pure function is then used by another function as a constant, it can be
directly inlined into the bytecode to avoid the overhead of a function call.
This is a module for applying some simple optimisations to function bytecode.
By promising that a function doesn't do certain things at run-time, it's
possible to apply optimisations that are not legal in the general case.
As a simple example, it's possible to promise that a function doesn't modify
(or care if anyone else modifies) any builtin functions by decorating it thus:
@promise.constant(__builtins__)
def function():
...
Such a promise will allow the builtins to be stored as direct object references
in the function bytecode, avoiding name lookups during function execution.
As another example, it's possible to promise that a function is pure; i.e. that
it's a simple algorithm for mapping input values to an output value:
@promise.pure()
def calculate(a,b):
return 2*a*a + 3*b + 7
If a pure function is then used by another function as a constant, it can be
directly inlined into the bytecode to avoid the overhead of a function call.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
promise-0.1.0.tar.gz
(16.5 kB
view details)
File details
Details for the file promise-0.1.0.tar.gz.
File metadata
- Download URL: promise-0.1.0.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2da3af5f1695077a8c130e5f05f308afae5030343925be2bdc9cffad995d678
|
|
| MD5 |
142830cf2fa7f870ff1735e60a82abbd
|
|
| BLAKE2b-256 |
2cbef9e01d392107df0e35f88c1d3ca4d9994a84d962214fe155c72bebe1e851
|