Build optimization for Python/SWIG interface#3220
Merged
Merged
Conversation
stevengj
reviewed
May 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.acandpython/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 byAX_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
.cxxfile size, shaving a few second off compilation.3. Reorder
SUBDIRSto unblock parallel buildsFile:
Makefile.am(lines 3-18)Currently:
src->tests->[libpympb]->python. Thetestsdirectory (17 C++ test programs) blockslibpympbfrom starting even thoughlibpympbonly depends onsrc/libmeep.la.4. Add
ccachesupport toconfigure.acAdd an
--enable-ccacheoption that prependsccacheto$CCand$CXX. Must go afterCXX=$MPICXXassignment so it wraps the final compiler. Default toauto(use if found, skip silently otherwise).For iterative development, this is the highest-impact single change: compiling the 50K+ line
meep-python.cxxgoes 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.