Skip to content

Commit f9bc4dd

Browse files
committed
added a note about the NOMINSIZE parameter
1 parent f44fca5 commit f9bc4dd

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

docs/building.rst

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,33 @@ source code contained in the file ``my_ext.cpp``.
7676

7777
.. code-block:: cmake
7878
79-
nanobind_add_module(my_ext my_ext.cpp)
79+
nanobind_add_module(my_ext my_ext.cpp)
8080
8181
:cmake:command:`nanobind_add_module` resembles standard CMake commands like
8282
``add_executable()`` and ``add_library()``. Any number of source code and
8383
header files can be declared when the extension is more complex and spread out
8484
over multiple files.
8585

86+
.. note::
87+
88+
One opinionated choice of :cmake:command:`nanobind_add_module` is that it
89+
optimizes the *size* of the extension by default (i.e., ``-Os`` is passed to
90+
the compiler regardless of the project-wide settings). You must specify the
91+
``NOMINSIZE`` parameter to the command to disable this behavior and, e.g.,
92+
optimize extension code for speed (i.e., ``-O3``):
93+
94+
.. code-block:: cmake
95+
96+
nanobind_add_module(my_ext NOMINSIZE my_ext.cpp)
97+
98+
The default is chosen this way since extension code usually wraps existing
99+
C++ libraries, in which the main computation takes place. Optimizing the
100+
bindings for speed does not measurably improve performance, but it does make
101+
the bindings *significantly* larger.
102+
103+
If you observe slowdowns when porting a pybind11 extension, or if your
104+
extension performs significant amounts of work within the binding layer,
105+
then you may want to experiment with passing the ``NOMINSIZE`` parameter.
106+
86107
The :ref:`next section <basics>` will review the contents of example module
87108
implementation in ``my_ext.cpp``.

0 commit comments

Comments
 (0)