Skip to content

perf(container): use iterator lookup instead of exception handling in Map/Dict#548

Merged
tqchen merged 1 commit intoapache:mainfrom
junrushao:junrushao/2026-04-13/exception-perf-in-map
Apr 14, 2026
Merged

perf(container): use iterator lookup instead of exception handling in Map/Dict#548
tqchen merged 1 commit intoapache:mainfrom
junrushao:junrushao/2026-04-13/exception-perf-in-map

Conversation

@junrushao
Copy link
Copy Markdown
Member

Summary

  • Replace try { n->at(k); } catch (...) with n->find(k) + iterator check in ffi.MapGetItemOrMissing and ffi.DictGetItemOrMissing
  • Avoids the overhead of throwing and catching exceptions on every missing-key lookup
  • No behavioral change: both paths return GetMissingObject() for absent keys

Closes #547

Test plan

  • uv run pytest -vvs tests/python -- 2088 passed, 38 skipped, 3 xfailed (no new failures)
  • Pre-commit hooks pass (clang-format, ASF header, file types, etc.)

… Map/Dict

Replace try/catch with find()+iterator check in `ffi.MapGetItemOrMissing`
and `ffi.DictGetItemOrMissing` to avoid exception overhead on missing keys.

Closes apache#547
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the ffi.MapGetItemOrMissing and ffi.DictGetItemOrMissing functions in src/ffi/container.cc to use iterator-based lookups with find instead of try-catch blocks around at. This modification improves efficiency by avoiding the overhead associated with exception handling for missing keys. I have no feedback to provide.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the ffi.MapGetItemOrMissing and ffi.DictGetItemOrMissing functions in src/ffi/container.cc to use the find method instead of at within a try-catch block. This change improves efficiency by avoiding the overhead of exception handling when a key is missing. I have no feedback to provide as there were no review comments.

@tqchen tqchen merged commit f26ff61 into apache:main Apr 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.

Perf: Map.get() key-miss incurs ~800ms cold-start on aarch64

2 participants