Skip to content

[GR-75959] Optimize C extension fastcall keyword-name handling.#901

Closed
graalvmbot wants to merge 12 commits into
masterfrom
fa/improve_c-pydantic-validate
Closed

[GR-75959] Optimize C extension fastcall keyword-name handling.#901
graalvmbot wants to merge 12 commits into
masterfrom
fa/improve_c-pydantic-validate

Conversation

@graalvmbot
Copy link
Copy Markdown
Collaborator

In macro benchmark c-pydantic-validate, I've observed a lot of time spent in small C API upcalls and a large number of short-lived managed objects that are only created to be handed to native code.

Main changes:

  • Convert several hot C API upcalls to static builtins to reduce call overhead.
  • Avoid acquiring the GIL for simple allocation upcalls where this is not needed.
  • Replace borrowed-value promotion with EnsurePythonObjectNode and avoid boxing primitive values when they can be represented as tagged native handles.
  • Create the METH_FASTCALL | METH_KEYWORDS keyword-name tuple directly as a native tuple with interned string elements.
  • Implement PyTuple_New in C and allocate a native PyTupleObject instead of creating a managed tuple with native sequence storage. Therefore, adjust tuple checks and type handling to account for native tuples.

Further, this includes small follow-up cleanups around native reference handling and inlining cutoffs that came up while reducing the C API overhead.

@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label May 29, 2026
@graalvmbot graalvmbot closed this May 29, 2026
@graalvmbot graalvmbot deleted the fa/improve_c-pydantic-validate branch May 29, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants