Skip to content

Build optimization for Python/SWIG interface#3220

Merged
stevengj merged 10 commits into
NanoComp:masterfrom
oskooi:make_fast_swig
May 23, 2026
Merged

Build optimization for Python/SWIG interface#3220
stevengj merged 10 commits into
NanoComp:masterfrom
oskooi:make_fast_swig

Conversation

@oskooi
Copy link
Copy Markdown
Collaborator

@oskooi oskooi commented May 22, 2026

The SWIG-generated Python interface is the slowest part of the Meep build. SWIG produces monolithic C++ files (typically 50K-100K+ lines) that are expensive to compile, and the current build configuration uses suboptimal SWIG flags and enforces unnecessary serial ordering across directories. The goal is to reduce wall-clock build time via changes to configure.ac and python/Makefile.am.

1. Reduce optimization level for SWIG-generated C++ compilation

The SWIG glue code is not performance-critical – hot loops live in libmeep.la. Compiling 50K+ lines at -O2/-O3 (set by AX_CXX_MAXOPT) wastes significant time on optimizations (vectorization, inlining) that don't benefit wrapper code.

2. Fix SWIG flags in both invocations

These flags primarily improve runtime call performance (10-30% for call-heavy code) but also modestly reduce generated .cxx file size, shaving a few second off compilation.

3. Reorder SUBDIRS to unblock parallel builds

File: Makefile.am (lines 3-18)

Currently: src -> tests -> [libpympb] -> python. The tests directory (17 C++ test programs) blocks libpympb from starting even though libpympb only depends on src/libmeep.la.

4. Add ccache support to configure.ac

Add an --enable-ccache option that prepends ccache to $CC and $CXX. Must go after CXX=$MPICXX assignment so it wraps the final compiler. Default to auto (use if found, skip silently otherwise).

For iterative development, this is the highest-impact single change: compiling the 50K+ line meep-python.cxx goes from 30-60s to ~1s on cache hit.

5. Suppress warnings on SWIG-generate code

SWIG-generated code produces many warnings that cannot be fixed. This is a developer-experience improvement rather than a build-time improvement.

Comment thread python/Makefile.am Outdated
@stevengj stevengj merged commit d2c7896 into NanoComp:master May 23, 2026
5 checks passed
@oskooi oskooi deleted the make_fast_swig branch May 23, 2026 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants