[MATLAB] Improve performance in outofprocess mode #2042
+206
−89
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.
Changes proposed in this pull request
This PR introduces several optimizations to the MATLAB interface that reduces execution time for the out-of-process mode, especially in reactor examples using MATLAB's own ode solver.
getArray,getString), eliminating repeated allocation overhead inclib.arrayobjects.ct.Kinetics,ct.ThermoPhase, andct.Mixturefor frequently accessed constants (nPhases,nReactions,nSpecies,nElements, etc.).ThermoPhasequantities (atomicWeights,molecularWeights,charges,minTemp,maxTemp).ismembercan be slow in MATLAB).If applicable, fill in the issue number this pull request is fixing
Partially addressed #2034
If applicable, provide an example illustrating new features this pull request is introducing
Profiling comparison (Mac OS 15.7, Apple M2 chip):
plug_flow_reactorexecution time reduced by ~60% inoutofprocessmode, but still an order of magnitude longer thaninprocessmode. These optimizations also speed upinprocessmode by a lesser extent, but time spent ongetArrayandcallstill reduced by ~30%.These are just a small subset of properties and methods that could be cached. They have a hit-rate of 100% until we allow the MATLAB interface to add species/reactions (but even with those the hit rate will be close to 100%). There are plenty elsewhere but I don't think the user would be calling them repeatedly. I'm still investigating whether setter methods with array inputs (such as
set.X) can be optimized with minimized memory copy.Checklist
scons build&scons test) and MATLAB examples execute successfully