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

IntType slowness (fixed ints) #90

Open
psrok1 opened this issue May 10, 2023 · 0 comments · May be fixed by #97
Open

IntType slowness (fixed ints) #90

psrok1 opened this issue May 10, 2023 · 0 comments · May be fixed by #97

Comments

@psrok1
Copy link
Member

psrok1 commented May 10, 2023

IntType is implementation of a concept to make a fixed-size int that behaves similarly to real int, so it's useful for reimplementation of code written in C language. It's natural that they're slower than native implementation, but current implementation is insanely slow because each operation creates new IntType object.

Each object initialization also comes with cutting value to the expected bitness.

value = int(value) & cls.mask

In the same time, base class of IntType is int which is immutable type.

Proposed solution is:

  • implement wrapper based on https://docs.python.org/3/library/numbers.html#numbers.Integral instead of deriving from int
  • make mutable IntType variant, so we avoid creating new objects in code that needs to work fast
  • check if wrapping ctypes.c_int works faster than applying mask for each operation that could be overflowing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant