All Projects → PhilipTrauner → nibbler

PhilipTrauner / nibbler

Licence: MIT License
Runtime Python bytecode optimizer. ⚡️

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to nibbler

portfolio-optimizer
A library for portfolio optimization algorithms with python interface.
Stars: ✭ 19 (-9.52%)
Mutual labels:  optimizer
madam
👩 Pytorch and Jax code for the Madam optimiser.
Stars: ✭ 46 (+119.05%)
Mutual labels:  optimizer
rethinking-bnn-optimization
Implementation for the paper "Latent Weights Do Not Exist: Rethinking Binarized Neural Network Optimization"
Stars: ✭ 62 (+195.24%)
Mutual labels:  optimizer
Post-Tweaks
A post-installation batch script for Windows
Stars: ✭ 136 (+547.62%)
Mutual labels:  optimizer
lookahead tensorflow
Lookahead optimizer ("Lookahead Optimizer: k steps forward, 1 step back") for tensorflow
Stars: ✭ 25 (+19.05%)
Mutual labels:  optimizer
gogo
Go to MIPS compiler, written in Go. Course project for Compiler Design (CS335).
Stars: ✭ 25 (+19.05%)
Mutual labels:  peephole
Cleaner
The only storage saving app that actually works! :D
Stars: ✭ 27 (+28.57%)
Mutual labels:  optimizer
soar
SQL Optimizer And Rewriter
Stars: ✭ 7,786 (+36976.19%)
Mutual labels:  optimizer
postcss-clean
PostCss plugin to minify your CSS with clean-css
Stars: ✭ 41 (+95.24%)
Mutual labels:  optimizer
pigosat
Go (golang) bindings for Picosat, the satisfiability solver
Stars: ✭ 15 (-28.57%)
Mutual labels:  optimizer
ada-hessian
Easy-to-use AdaHessian optimizer (PyTorch)
Stars: ✭ 59 (+180.95%)
Mutual labels:  optimizer
AdaBound-tensorflow
An optimizer that trains as fast as Adam and as good as SGD in Tensorflow
Stars: ✭ 44 (+109.52%)
Mutual labels:  optimizer
falcon
A WordPress cleanup and performance optimization plugin.
Stars: ✭ 17 (-19.05%)
Mutual labels:  optimizer
adamwr
Implements https://arxiv.org/abs/1711.05101 AdamW optimizer, cosine learning rate scheduler and "Cyclical Learning Rates for Training Neural Networks" https://arxiv.org/abs/1506.01186 for PyTorch framework
Stars: ✭ 130 (+519.05%)
Mutual labels:  optimizer
sam.pytorch
A PyTorch implementation of Sharpness-Aware Minimization for Efficiently Improving Generalization
Stars: ✭ 96 (+357.14%)
Mutual labels:  optimizer
EAGO.jl
A development environment for robust and global optimization
Stars: ✭ 106 (+404.76%)
Mutual labels:  optimizer
Windows11-Optimization
Community repository, to improve security and performance of Windows 10 and windows 11 with tweaks, commands, scripts, registry keys, configuration, tutorials and more
Stars: ✭ 17 (-19.05%)
Mutual labels:  optimizer
simplu3D
A library to generate buildings from local urban regulations.
Stars: ✭ 18 (-14.29%)
Mutual labels:  optimizer
gfsopt
Convenient hyperparameter optimization
Stars: ✭ 12 (-42.86%)
Mutual labels:  optimizer
goga
Go evolutionary algorithm is a computer library for developing evolutionary and genetic algorithms to solve optimisation problems with (or not) many constraints and many objectives. Also, a goal is to handle mixed-type representations (reals and integers).
Stars: ✭ 39 (+85.71%)
Mutual labels:  optimizer

nibbler


Python 3.7 PyPI version Not production ready Travis status

nibbler is a runtime bytecode optimizer.

It explores the concept of using existing Python syntax features such as type annotations and decorators to speed up code execution by running additional bytecode optimization passes that make use of runtime context provided through these means.

Optimization passes

  • inline
    Inlines parameter-less calls to functions that are decorated with @nibbler.inline.
  • constantize_globals
    Copies the value of globals that were marked constant (with a Constant type annotation or with the @nibbler.constant decorator) into the co_consts tuple of functions that would normally have to access the global namespace, which speeds up variable access. This also applies to builtins (any, all, print, ...).
  • precompute_conditionals
    Strips out conditionals that test constants which the peephole optimizer doesn't pick up on.
  • global_to_fast
    Transforms global variable loads to local variable loads if a local variable with the same name exists (mostly a cleanup pass for inline)
  • peephole
    Invokes the Python peephole optimizer with additional context.

Usage

from typing import Iterable

from nibbler import Constant, Nibbler

DEBUG: Constant[bool] = False

nibbler = Nibbler(globals())


@nibbler.inline
def square(number: int, base: int) -> int:
    result = number ** base
    return result


@nibbler.nibble
def sequential_square(numbers: Iterable[int]) -> int:
    product = 0
    base = 2
    for number in numbers:
        square()

        if DEBUG:
            print(result)

        product += result

    print(f"Result: {product}")

    return product


sequential_square(range(4))

Result: 14

Examining the function bytecode reveals which optimizations nibbler has performed:

  2           0 LOAD_CONST               1 (0)
              2 STORE_FAST               1 (product)

  3           4 LOAD_CONST               2 (2)
              6 STORE_FAST               2 (base)

  4           8 SETUP_LOOP              28 (to 38)
             10 LOAD_FAST                0 (numbers)
             12 GET_ITER
        >>   14 FOR_ITER                20 (to 36)
             16 STORE_FAST               3 (number)

  5          18 LOAD_FAST                3 (number)
             20 LOAD_FAST                2 (base)
             22 BINARY_POWER
             24 STORE_FAST               4 (result)

  6          26 LOAD_FAST                1 (product)
             28 LOAD_FAST                4 (result)
             30 INPLACE_ADD
             32 STORE_FAST               1 (product)
             34 JUMP_ABSOLUTE           14
        >>   36 POP_BLOCK

  8     >>   38 LOAD_CONST               5 (<built-in function print>)
             40 LOAD_CONST               3 ('Result: ')
             42 LOAD_FAST                1 (product)
             44 FORMAT_VALUE             0
             46 BUILD_STRING             2
             48 CALL_FUNCTION            1
             50 POP_TOP

  9          52 LOAD_FAST                1 (product)
             54 RETURN_VALUE
  • The square function was inlined (inline) (18-24)
  • Conditional (if DEBUG) was stripped out, because DEBUG was declared a constant (precompute_conditionals) (26)
  • The print function was promoted to a function-level constant (constantize_globals) (38)

Installation

pip3 install nibbler

FAQ

  • Is this production ready?
    Hell no.
  • Why is it called nibbler?
    ¯\_(ツ)_/¯

Prior Art

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].