Skip to content

IntType slowness (fixed ints) #90

@psrok1

Description

@psrok1

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions