You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "junrushao (via GitHub)" <gi...@apache.org> on 2026/04/14 05:32:15 UTC
[I] Perf: `Map.get()` key-miss incurs ~800ms cold-start on aarch64 [tvm-ffi]
junrushao opened a new issue, #547:
URL: https://github.com/apache/tvm-ffi/issues/547
## Summary
`tvm_ffi.Map.get()` on a key miss is **~100,000x slower** on the first call on **aarch64** (Grace Hopper) due to DWARF unwinding table parsing triggered by the `try/catch` pattern in `MapGetItemOrMissing`.
## Reproducer
```python
import time, tvm_ffi
m = tvm_ffi.Map({"a": 1})
t0 = time.perf_counter()
m.get("nonexistent")
print(f"1st miss: {(time.perf_counter()-t0)*1000:.0f} ms") # ~780ms on aarch64
t0 = time.perf_counter()
m.get("nonexistent")
print(f"2nd miss: {(time.perf_counter()-t0)*1000:.3f} ms") # ~0.07ms
```
Output on aarch64 (Grace Hopper, Linux 6.14.0-1008-nvidia-64k):
```
1st miss: 782 ms
2nd miss: 0.075 ms
```
## Root Cause
`MapGetItemOrMissing` in `src/ffi/container.cc:196` uses exception-based control flow for key misses:
```cpp
.def("ffi.MapGetItemOrMissing",
[](const ffi::MapObj* n, const Any& k) -> Any {
try {
return n->at(k); // throws on miss
} catch (const tvm::ffi::Error& e) {
return GetMissingObject(); // caught here
}
})
```
On aarch64, C++ exceptions use DWARF-based unwinding. The first `throw` in a process triggers lazy parsing of `.eh_frame` / `.eh_frame_hdr` sections across all loaded shared libraries. This is a one-time cost but it's ~800ms on a typical tilus installation (which loads `libtvm_ffi.so`, CUDA libraries, torch, etc.).
For comparison, `Map.__contains__` uses `count()` (no exception) and takes 0.014ms even on the first call.
## Impact
In the tilus compilation pipeline, `bound_aware_simplify` calls `Map.get()` on `Analysis` metadata maps (which are `frozendict` stored in `@py_class` fields, converted to `tvm_ffi.Map` by the FFI layer). The first key miss adds ~800ms to the Tilus IR optimization phase. We are currently working around this by converting to Python `dict` before lookups, but the upstream fix would benefit all `Map.get()` callers.
## Environment
- Platform: aarch64 (NVIDIA Grace Hopper)
- Python: 3.13
- tvm-ffi: 0.1.11.dev19+g2987899a5%
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [I] Perf: `Map.get()` key-miss incurs ~800ms cold-start on aarch64 [tvm-ffi]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen closed issue #547: Perf: `Map.get()` key-miss incurs ~800ms cold-start on aarch64
URL: https://github.com/apache/tvm-ffi/issues/547
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [I] Perf: `Map.get()` key-miss incurs ~800ms cold-start on aarch64 [tvm-ffi]
Posted by "junrushao (via GitHub)" <gi...@apache.org>.
junrushao commented on issue #547:
URL: https://github.com/apache/tvm-ffi/issues/547#issuecomment-4241582852
Should be fixed by: https://github.com/apache/tvm-ffi/pull/548
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org