Skip to content

feat: move remaining non-template definitions to -inl.h files - #6189

Merged
henryiii merged 1 commit into
pybind:masterfrom
henryiii:feat/precompile-remaining-non-template
Oct 9, 2026
Merged

henryiii merged 1 commit into
pybind:masterfrom
henryiii:feat/precompile-remaining-non-template

Conversation

@henryiii

@henryiii henryiii commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

I believe this was another 5% or so for pytorch.

🤖 AI text below 🤖

Description

Follow-up to the precompiled-mode series (#6135–#6138). Weak-symbol counts on PyTorch's torch_python showed that some non-template code was still compiled in most TUs in precompiled mode. This moves it to -inl.h files:

  • gil_scoped_acquire / gil_scoped_release (new gil-inl.h)
  • type_record's constructor and add_base (new attr-inl.h)
  • clean_type_id (new detail/typeid-inl.h)
  • the cpp_conduit helpers (new detail/cpp_conduit-inl.h)
  • type_caster_generic's module-local loaders, the error_already_set constructor, the non-template module_ members, and get_shared_data / set_shared_data

Most of these were already PYBIND11_NOINLINE. The new -inl.h files are compiled from the existing src/ files, so the library does not get more TUs. tools/check_inl_headers.py now allows PYBIND11_HAS_CXXABI_H and GRAALPY_VERSION_NUM. The library and the modules always see the same values for these macros.

Suggested changelog entry:

  • Moved more non-template definitions (GIL scoped guards, type_record, cpp_conduit helpers, module_ members, and others) out of line in the opt-in precompiled mode.

Weak-symbol counts on PyTorch's torch_python showed these were still
compiled in most TUs in precompiled mode: gil_scoped_acquire/release,
type_record, clean_type_id, the cpp_conduit helpers, type_caster_generic's
module-local loaders, error_already_set's constructor, module_'s
non-template members, and get/set_shared_data. Most were already
PYBIND11_NOINLINE. The new -inl.h files are compiled from existing src/
files, so the library does not gain TUs.

Assisted-by: ClaudeCode:claude-opus-5-5

@rwgk rwgk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

codex GPT-6.1-Sol ultra:

No actionable findings, reviewed at 5a3d18c.

I reviewed all 22 changed files, including GIL ownership, exception construction, module-local and conduit conversions, configuration guards, source wiring, and packaging.

@henryiii
henryiii merged commit 6254086 into pybind:master Oct 9, 2026
145 of 146 checks passed
@henryiii
henryiii deleted the feat/precompile-remaining-non-template branch October 9, 2026 12:21
@github-actions github-actions Bot added the needs changelog Possibly needs a changelog entry label Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs changelog Possibly needs a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants