-
Notifications
You must be signed in to change notification settings - Fork 2.2k
pybind11_add_module(): OPT_SIZE argument for size-based optimization #2463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
tools/pybind11NewTools.cmake
Outdated
target_link_libraries(${target_name} PRIVATE pybind11::opt_size) | ||
endif() | ||
|
||
# Avoid the -D${target_name}_EXPORTS definition that CMake adds by default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these harmful, though? I would assume they do nothing if never used, and someone might expect them to be there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, fair enough -- I'll delete them again.
f5cf30b
to
eb7b75f
Compare
This is why changlog entries in PRs can be a bit of a pain. I've never come up with a reasonable solution, though. Since both of my merged PRs have affected this, I've rebased for you. (If you need to update, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, adding my checkmark :-)
Merged with some documentation improvements following @YannickJadoul's question. I got rid of the originally proposed change to remove the -D..._EXPORTS flag. |
This PR adds way of switching this specific target over to “optimize size” flags (-Os) no matter what the project itself uses (except in debug mode, where optimizations remain disabled). Performance within bindings is usually not that critical, and this can make a quite substantial difference in projects that are weighted down by heavy (10-100MB) python extension libraries. I’m seeing ~25% size reduction just from that.
The PR also contains two other very minor changes:
cmake appends a dummy define -D${target_name}_EXPORTS when compiling shared libraries. These are often not needed, especially not for binding code. I've added directives that remove them.
pybind11 prints two redundant lines when included by a parent project (via
add_subdirectory
), I've deleted one of them.