pybind / pybind/pybind11

Would you consider merging a patch that optionally splits pybind11 into declarations vs definitions in a backwards compatible opt-in manner?

Open
#2,322 23 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

Edit: PR at: https://github.com/pybind/pybind11/pull/2445

Hello!

TL;DR: a split into declarations/definitions would save a lot of time/money for the gem5 project which I work on. I already have a prototype which reduces build time by 40% from 25 minutes to 15 minutes.

If I were to send a patch that does this split, in an opt-in way that does not affect existing users at all, would you consider merging it?

I would like to know if this is reasonable before I sink time into something that won't get reviewed.

The proposed implementation is: I would just check if a macro if defined before inclusion of pybind11.hpp, say PYBIND11_HPP.

If the macro is defined, only declarations will be enabled, and therefore you won't get object redefinitions. So usage would be in a project that wants to opt-in would be like this.

In one single file of the project which gets linked at the end:

pybind11.cpp

#include <pybind11/pybind11.h>

This will be the only file to contain definitions of non-templated stuff that does not need to be defined in headers.

Then, on every other file of the project, include as:

#define PYBIND11_HPP 1
#include <pybind11/pybind11.h>

which will only expose declarations and not definitions, therefore preventing a ton of object redefinitions.

More details about the gem5 project can be found at: https://github.com/pybind/pybind11/issues/708#issuecomment-630422294 maybe this issue is a duplicate of that one, but I'm not sure, feel free to close if you think yes. I'm just waiting for another long build and decided to annoy you a bit :-) If you promise to review, I will send a patch.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing PR #2445 and the proposed inclusion pattern in pybind11/pybind11.h, including the example pybind11.cpp file. Check the related discussion in issue #708 for context. Done means an opt-in declarations-versus-definitions split that preserves existing users and reduces gem5 build time without object redefinitions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
build-system, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.