llvmlite icon indicating copy to clipboard operation
llvmlite copied to clipboard

Classes should use `__slots__` in order to reduce memory footprint.

Open ArachnidAbby opened this issue 2 years ago • 2 comments


Feature request

It would be fairly simple to add the __slots__ variable to most of or all the classes.

reasons to add __slots__

  • reduces memory footprint of classes (biggest advantage imo)
  • they are slightly faster
  • helps with IDE type checkers

If you accept this idea, I can do it for you and make a pull request with the changes made.

ArachnidAbby avatar Nov 07 '22 15:11 ArachnidAbby

Are you having memory or performance issues when using llvmlite? I'm concerned that adding __slots__ might break use cases where additional attributes are attached to instances, and add additional maintenance overhead.

gmarkall avatar Nov 07 '22 15:11 gmarkall

Are you having memory or performance issues when using llvmlite? I'm concerned that adding __slots__ might break use cases where additional attributes are attached to instances, and add additional maintenance overhead.

In terms of memory, yes, but I'm not 100% sure __slots__ would solve that, but it could help to reduce it. I found an old screenshot where I was trying to figure out why the memory usage in my app was so high. It turns out llvmlite.binding is a 37mb import, and running llvmlite.binding.create_mcjit_compile(...) alone used 3.5mb. Luckily I could remove that line since it turned out I didn't need it (I was following some tutorial article when first learning how to use llvmlite).

Edit: this doesnt seem to be llvmlite's fault here. I was misunderstanding the cause of the issue.

ArachnidAbby avatar Nov 08 '22 21:11 ArachnidAbby