Skip to content

Optimize Python key extraction using cast instead of extract#20

Merged
bisho merged 1 commit into
mainfrom
03-26-avoid_extract_in_favor_of_faster_cast
Mar 26, 2026
Merged

Optimize Python key extraction using cast instead of extract#20
bisho merged 1 commit into
mainfrom
03-26-avoid_extract_in_favor_of_faster_cast

Conversation

@bisho
Copy link
Copy Markdown
Member

@bisho bisho commented Mar 26, 2026

Motivation / Description

Optimize key extraction performance by avoiding expensive error conversions when checking Python object types.

This is minimal but measurable -.2us and best practices (pyo3 recommends cast)

Changes introduced

  • Replace extract() calls with cast() in extract_key() function to avoid costly PyDowncastError to PyErr conversions
  • Add explicit imports for PyBytes and PyString types to support the new casting approach
  • Maintain the same functionality while improving performance for the success path when extracting string and bytes keys

Copy link
Copy Markdown
Member Author

bisho commented Mar 26, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@bisho bisho marked this pull request as ready for review March 26, 2026 11:42
@bisho bisho requested a review from a team March 26, 2026 12:51
@bisho bisho mentioned this pull request Mar 26, 2026
Copy link
Copy Markdown
Member Author

bisho commented Mar 26, 2026

Merge activity

  • Mar 26, 12:58 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Mar 26, 12:59 PM UTC: @bisho merged this pull request with Graphite.

@bisho bisho merged commit de5b6a7 into main Mar 26, 2026
17 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.

2 participants