Skip to main content

Profila: a profiler for Numba

This profiler is sponsored by my book on writing fast low-level code in Python, which uses Numba for most of its examples.

Here's what Profila output looks like:

$ python -m profila annotate -- scripts_for_tests/simple.py
# Total samples: 328 (54.9% non-Numba samples, 1.8% bad samples)

## File `/home/itamarst/devel/profila/scripts_for_tests/simple.py`
Lines 10 to 15:

  0.3% |     for i in range(len(timeseries)):
       |         # This should be the most expensive line:
 38.7% |         result[i] = (7 + timeseries[i] / 9 + (timeseries[i] ** 2) / 7) / 5
       |     for i in range(len(result)):
       |         # This should be cheaper:
  4.3% |         result[i] -= 1

You can also use it with Jupyter!

Beyond this README, you can also read this introductory article with a more detailed example and explanations.

TL;DR limitations: Linux only, and only single-threaded Numba can be profiled currently, parallel functions are not yet supported.

Installation

Currently Profila works on Linux only.

  • On macOS you can use Docker, Podman, or a Linux VM.
  • On Windows you can use Docker, Podman, or probably WSL2.

Install this library using pip:

pip install profila

Then, have Profila install some dependencies it needs, specifically an older version of gdb; this will not interfere with your system gdb. (This is necessary due to some bad interactions with newer gdb and Numba that will hopefully go away someday.)

python -m profila setup

Usage

Jupyter profiling

First, before you import numba you should:

%load_ext profila

Then define your functions as usual:

from numba import njit

@njit
def myfunc(arr):
    # ... your code here ...

You probably want to call your Numba function at least once, so profiling doesn't measure compilation time:

myfunc(DATA)

Then, you can profile a specific cell using the %%profila magic, e.g.

%%profila
# Make sure we run this enough to get good measurements:
for i in range(100):
    myfunc(DATA)

Command-line profiling

If you usually run your script like this:

$ python yourscript.py --arg1=200

Instead run it like this:

$ python -m profila annotate -- yourscript.py --arg1=200

If you usually run your script like this, with -m:

$ python -m yourpackage --arg1=200

Instead run it like this:

$ python -m profila annotate -- -m yourpackage --arg1=200

Sampling is done every 10 milliseconds, so you need to make sure your Numba code runs for a sufficiently long time. For example, you can run your function in a loop until a number of seconds has passed:

from time import time

@njit
def myfunc():
    # ...

start = time()
# Run for 3 seconds:
while (time() - start) < 3:
    myfunc()

The limitations of profiling output

  • Parallel Numba code will not be profiled correctly; at the moment only single-threaded profiling is supported.
  • GPU (CUDA) code is not profiled.

Beyond that:

1. The compiled code isn't the same as the input code

Compiled languages like Numba do optimization passes and transform the code to make it faster. That means the running code doesn't necessarily map one to one to the original code; different lines might be combined, for example.

As far as I can tell Numba does give you a reasonable mapping, but you can't assume the source code maps one to one to executed code.

2. Adding the necessary info can change the performance of your code

In order to profile, additional info needs to be added during compilation; specifically, the NUMBA_DEBUGINFO env variable is set. This might change runtime characteristics slightly, because it increases the memory size of the compiled code.

3. Compiled code is impacted by CPU effects that aren't obvious from profiling results

Instruction-level parallelism, branch mispredictions, SIMD, and the CPU memory caches all have a significant impact on runtime performance, but the profiling result doesn't always make it clear that's the problem. I'm writing a book about this if you want to learn more.

Changelog

v0.3.2

  • python -m profila setup should now work correctly in Conda environments.
  • Support for latest IPython.
  • Support for Python 3.13.

v0.3.1

Documentation improvements.

v0.3.0

Bug fixes:

  • Work on newer versions of Linux, like Ubuntu 24.04 and RHEL 9, in the face of issues with newer gdb.
  • Fixed occasional error TypeError: argument of type 'NoneType' is not iterable.

v0.2.1

Bug fixes:

  • Run Python using sys.executable, so it works in more environments. Thanks to Jeremiah England for the bug report.

v0.2.0

Added support for Jupyter profiling.

v0.1.0

Initial release.

Metadata

Release files for profila 0.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for profila 0.3.4
File Size Uploaded Provenance Actions
profila-0.3.4.tar.gz 20.6 kB With provenance Details for profila-0.3.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for profila 0.3.4
File Interpreter ABI Platform Actions
profila-0.3.4-py3-none-any.whl Python 3 none any Details for profila-0.3.4-py3-none-any.whl

Total release size: 37.1 kB

Release files / profila-0.3.4.tar.gz

Download URL profila-0.3.4.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d4d0e6657c4142cdac600a1866b9d35db44b03d6f9321dda636e0ad9617619d3
BLAKE2b-256 checksum
How to use checksums
10d0ae101258db0b1f4d607df1021ca9b7c6a7ff79c44554456e3ac331e2ce29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 26, 2026.

Transparency log

Release files / profila-0.3.4-py3-none-any.whl

Download URL profila-0.3.4-py3-none-any.whl
Size 16.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96ee41c3dc718eb2d70a596fae9b4806fad3cf7a9b123185be318e955dcbe834
BLAKE2b-256 checksum
How to use checksums
ebad1a1ed78ed1fe78568632c2671f60d1ae5f9bdbe7797421d4a21a199b62f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 26, 2026.

Transparency log

Security for profila 0.3.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for profila-0.3.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page