question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Caching a function that takes in a jitclass instance

See original GitHub issue
@jitclass([])
class NumbaClass():
    def __init__(self):
        pass

@njit(cache=True)
def calc(numbaObj):
    pass

numbaObject = NumbaClass()
calc(numbaObject)

Each time the script above is ran, it generates a new cache entry for “calc”, likely because NumbaClass.class_type.instance_type changes on every run, making the cache flag effectively not work and growing the __pycache__ folder on every run (mine eneded up being a few gigs). Is there a work-around for this? Numba 0.51.2

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
stuartarchibaldcommented, Nov 27, 2020

Thanks for the report. I think your assessment of the situation is correct. Should probably warn users this doesn’t work and disable caching.

0reactions
valtroncommented, Apr 12, 2022

This is due to id(self) being part of the jitclass’ name:https://github.com/numba/numba/blob/f04f4b164887e5aa5ffeeed1bef317e13ec995f8/numba/core/types/misc.py#L425-L426

I looked through the history but couldn’t figure out why it’s needed. I saw at some point early on (when jitclasses were being added), the sig didn’t include the fielddesc. But since it does include it now, it seems like that should be enough to fully define the type’s layout? Is there some problem I’m not seeing?

I tried removing id(self), which makes caching work, and adding/removing fields works as expected too (just makes new cache entries).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cache jitted function with jitclass argument - Numba Discussion
There's an open issue about this: Caching a function that takes in a jitclass instance · Issue #6522 · numba/numba · GitHub, unfortunately, ......
Read more >
Reducing numba @jitclass compilation time (with caching?)
My guess is that because State isn't cached it compiles each time, and then the dependent functions requires compilation. Is there any solution ......
Read more >
Compiling Python classes with @jitclass - Numba
All methods of a jitclass are compiled into nopython functions. The data of a jitclass instance is allocated on the heap as a...
Read more >
Compiling Python classes with @jitclass
We call the resulting class object a jitclass. All methods of a jitclass are compiled into nopython functions. The data of a jitclass...
Read more >
numba/numba-dev - Gitter
it wouldn't if you force use of jitclass ... that I made good progress on extending the cache invalidation to function dependencies here...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found