Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH - Numba compilation at import instead of execution time #148

Closed
Badr-MOUFAD opened this issue Mar 7, 2023 · 1 comment
Closed

ENH - Numba compilation at import instead of execution time #148

Badr-MOUFAD opened this issue Mar 7, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@Badr-MOUFAD
Copy link
Collaborator

I discovered that we can pre-compile numba functions without having to run them by specifying the signature of the function in @njit

import time
import numpy as np
from numba import njit


@njit("f8(f8[:])")
def compute_sum(arr):
    sum = 0.
    for element in arr:
        sum += element
    return sum


arr = np.random.randn(10_000)

start = time.perf_counter()
# Runned without overhead
compute_sum(arr)  
end = time.perf_counter()

print("total elapsed time:", end - start)

By doing so, we transfer the entire compilation overhead to import time, hence, releasing our ourself from the first run to cache numba compilation (as done in benchmarks).

This is to be considered yet requires attention as we have many functions

  • hence the import overhead might be huge unless we control when/where modules are imported
  • many functions, some with long signatures, hence readability, maintainability, and applicability challenges

The advantages are clear for small examples, I tried it also for a quite big code. However, I don't have much visibility on the impact of that on the whole package.


Also related to #106

@Badr-MOUFAD Badr-MOUFAD added the enhancement New feature or request label Mar 7, 2023
@mathurinm
Copy link
Collaborator

mathurinm commented May 31, 2024

I am -0.5 on this: it requires more code maintenance, it may compile too much stuff, and it does not reduce the time taken by compilation in the script.

The fact that it makes benchmarking easier is not enough IMO (we try to target users now, more than optimization researchers).

@Badr-MOUFAD @QB3 I'll close this, reopen if you feel againt it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants