Skip to content

[PERF] Avoid backtraces for type-key and dtype probes - #975

Merged
tqchen merged 1 commit into
apache:mainfrom
cyx-6:codex/zihao-type-check-performance
Nov 15, 2026
Merged

tqchen merged 1 commit into
apache:mainfrom
cyx-6:codex/zihao-type-check-performance

Conversation

@cyx-6

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

Copy link
Copy Markdown
Contributor

Type-key and dtype probes can capture expensive error backtraces for expected misses.

Query type keys without raising, and add tvm_ffi.dtype.try_parse(text) -> dtype | None. It returns the parsed dtype directly on success and None for an invalid dtype string, avoiding a second parse after a successful probe. The registered ffi.DataTypeTryParse function returns Optional<DLDataType>; there is no boolean can-parse API.

Dtype parsing reuses ErrorBuilder through a file-local TVM_FFI_THROW_NO_BACKTRACE macro. Invalid dtype construction still raises ValueError with the existing message, without capturing a parser backtrace. Other errors propagate. No new C API or Cython wrapper is required.

Validation: editable C++/Cython build succeeded; dtype and object tests: 161 passed, 1 skipped. Type checking, Ruff, C++ formatting, and whitespace checks passed.

@cyx-6 cyx-6 changed the title [PERF] Avoid probe backtraces and accelerate Object type checks [PERF] Avoid backtraces for type-key and dtype probes Nov 14, 2026
@cyx-6
cyx-6 force-pushed the codex/zihao-type-check-performance branch 3 times, most recently from 9ffd289 to bb128ba Compare November 14, 2026 14:38

@tqchen tqchen left a comment

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.

streamline the pr

Comment thread include/tvm/ffi/c_api.h Outdated
* An error outside the parse, such as an unregistered custom type, is raised as
* TVMFFIDataTypeFromString raises it.
* \param str The string to convert.
* \param out The output DLDataType.

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.

Move to use ffi function

Comment thread src/ffi/dtype.cc
*scan = str.data() + 6;
TVM_FFI_ICHECK(str.data() == tmp);
if (**scan != '[') {
TVM_FFI_THROW(ValueError) << "expected opening brace after 'custom' type in" << str;

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.

add TVM_FFI_THROW_NO_BACKTRACE, keep private to file for now

@cyx-6
cyx-6 force-pushed the codex/zihao-type-check-performance branch from bb128ba to e1b5548 Compare November 14, 2026 15:11
Comment thread src/ffi/dtype.cc Outdated
}

TVM_FFI_STATIC_INIT_BLOCK() {
reflection::GlobalDef().def("ffi.DataTypeParses", [](const String& str) {

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.

DataTypeCanParse

@cyx-6
cyx-6 force-pushed the codex/zihao-type-check-performance branch 2 times, most recently from 4196403 to e292404 Compare November 14, 2026 15:24
@cyx-6
cyx-6 force-pushed the codex/zihao-type-check-performance branch from e292404 to 7aecb09 Compare November 14, 2026 15:38
@tqchen
tqchen merged commit e1ba35f into apache:main Nov 15, 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