I just committed/tested a small change currently available in swig-CVS
which allows to compile your swig module using the
GCC -fvisibility=hidden option, present in gcc-3.4 an later.
If you have a very large interface, or that uses a lot of templates, or
uses the std/stl library a lot too, try compiling with this new
option, ie, after regenerating your module using swg-CVS,
compile it as
g++ -fvisibility=hidden .... -c mymodule_wrap.cc
and check the differences in sizes and loading time.
For the simple and small python/std_containers.i test case, we
Exported symbols (nm -D <file>.so | wc -l):
real 0m0.050s user 0m0.039s sys 0m0.005s _std_containers.so
real 0m0.039s user 0m0.026s sys 0m0.007s
Read http://gcc.gnu.org/wiki/Visibility for more details.
The improvements are not as dramatic as for the boost people, which use
templates than us, but is something...
On 2006-03-01, Marcelo Matus <mmatus@...> wrote:
> I just committed/tested a small change currently available in swig-CVS
> which allows to compile your swig module using the
> GCC -fvisibility=hidden option, present in gcc-3.4 an later.
> If you have a very large interface, or that uses a lot of templates, or
> uses the std/stl library a lot too, try compiling with this new
I don't really have any of these, except that a lot of my methods
handle std::string, but I thought I'd see how much difference it made
anyhow. Perhaps these numbers will serve to indicate how useful this is
for people with projects similar to mine.
Building _xapian.so for python:
-O2 -g: 1751823
after strip --strip-unneeded: 526920
-O2 -g: 1736671
after strip --strip-unneeded: 512520
So that's 2.7% reduction in stripped size, which I think makes it worth
the effort of writing a suitable configure test, especially as it
benefits all the wrapped languages. Thanks Marcelo!
"nm -D" says that -fvisibility reduces the number of symbols from 544 to
386. I don't really have a suitable testcase to perform tests of
execution time (I suspect the speed-up will be small enough that it'll
be hard to measure accurately.)