Skip to content

[PERF] Speed up Object instance and subclass checks - #976

Merged
tqchen merged 2 commits into
apache:mainfrom
cyx-6:codex/object-type-checks
Nov 14, 2026
Merged

tqchen merged 2 commits into
apache:mainfrom
cyx-6:codex/object-type-checks

Conversation

@cyx-6

@cyx-6 cyx-6 commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Object instance and subclass checks incur ABCMeta overhead even when no virtual subclasses are registered. Negative subclass checks can recursively traverse large class hierarchies.

Use MRO checks for Object instance and subclass checks, falling back to ABCMeta when virtual subclasses are registered or a subclass hook is defined. Add coverage for non-Object values, collection ABCs, virtual subclasses, and subclass hooks.

@cyx-6
cyx-6 force-pushed the codex/object-type-checks branch from beecc22 to 488c7f7 Compare November 14, 2026 14:36
@cyx-6
cyx-6 force-pushed the codex/object-type-checks branch from 488c7f7 to 396c93f Compare November 14, 2026 14:39
Comment thread python/tvm_ffi/cython/object.pxi Outdated
# Until one is, ``isinstance`` and ``issubclass`` against an Object class follow the MRO alone, which
# is what ``ABCMeta`` answers then too, without its Python-level check: a negative ``issubclass``
# there walks every subclass of the class, adding overhead for large class hierarchies.
cdef bint _OBJECT_ABC_VIRTUAL = False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to add an short example explaination of the checks

@tqchen
tqchen merged commit d74a25d into apache:main Nov 14, 2026
9 checks passed
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 this pull request may close these issues.

3 participants