Skip to content

Speed up MATLAB mex build by caching shared C object files - #60

Merged
benfulcher merged 1 commit into
mainfrom
speed-up-matlab-mex-compile
Aug 21, 2026
Merged

Speed up MATLAB mex build by caching shared C object files#60
benfulcher merged 1 commit into
mainfrom
speed-up-matlab-mex-compile

Conversation

@benfulcher

Copy link
Copy Markdown
Collaborator

Summary

  • wrap_Matlab/mexAll.m compiled each of the 24 feature mex files as a separate mex call, and every call was handed the full set of ~24 shared C source files (helper_functions.c, stats.c, fft.c, ...) alongside M_wrapper.c and the one feature-specific wrapper -- so every shared file was recompiled from scratch 24 times over.
  • This compiles the shared files to object files once with mex -c -outdir, then links each small per-feature wrapper against the cached objects.
  • ~3.4x faster locally (62s -> 18s on macOS/clang). Output verified bit-identical against the previous build (same feature values on a fixed seed, across a spread of feature functions).

Test plan

  • Ran mexAll end-to-end on macOS, all 24 features compile successfully
  • Compared feature outputs (CO_FirstMin_ac, DN_Mean, SP_Summaries_welch_rect_centroid) on a fixed-seed input against a build from the unmodified mexAll.m -- bit-identical
  • Not tested on Windows/Linux -- the change only adds -c -outdir object-compile steps ahead of the existing per-feature mex calls, no new platform-specific logic

mexAll.m recompiled the ~24 shared C source files (helper_functions.c,
stats.c, fft.c, ...) from scratch for every one of the 24 features, since
each mex() call was handed the full includeFiles list. Compile those shared
files to object files once with mex -c, then link each feature's small
wrapper against the cached objects instead.

~3.4x faster locally (62s -> 18s on macOS/clang), output verified
bit-identical against the previous build.
@benfulcher
benfulcher merged commit fc45e60 into main Aug 21, 2026
2 checks passed
benfulcher added a commit to benfulcher/hctsa that referenced this pull request Aug 21, 2026
…; bump catch22

startup.m now fetches the catch22 git submodule automatically (streaming
git's progress) if it's missing, rather than only warning about it -- this
fires whether startup is called directly or via install.m, so it's no
longer possible to skip install.m and hit a silent addpath warning.
install.m's now-redundant interactive prompt for the same check is removed.

TISEAN and ripser now print inline in the same comma-separated toolbox list
as everything else in startup.m, instead of separate "System path to..."
lines with the full path.

Bumped the catch22 submodule to pick up an upstream fix (merged as
DynamicsAndNeuralSystems/catch22#60) that caches shared C object files
during the MATLAB mex build instead of recompiling them from scratch for
every one of the 24 features (~3x faster, verified bit-identical output).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant