Is it just me or is the fancy exit messaging in fsolve creating huge overhead?I imagine this might impact other optim toolbox functions but I have only tested with fsolve so far. The profiler shows approx. 35% of the fsolve run time spent in a call to fsolve>createExitMsg. Replacing the two relevant lines with something like the below resulted in about 30% overall speedup in my problem (calling fsolve many times in a loop):
if EXITFLAG > 0 % if we think we converged:
% Call createExitMsg with appended additional information on the closeness
% to a root.
if Resnorm > sqrtTolFunValue msgData = internalFlagForExitMessage(algorithmflag == 2,msgData,EXITFLAG); EXITFLAG = -2; end %OUTPUT.message = createExitMsg(msgData{:},Resnorm,optionFeedback.TolFunValue,sqrtTolFunValue);
OUTPUT.message = msgData;else %OUTPUT.message = createExitMsg(msgData{:});
OUTPUT.message = msgData;end
In the above I commented out the offending calls and replaced with just saving the msgData cell.
Questions:
- Is anyone else seeing this behavior
- Is my replacement likely to break something in unexpected ways?
- Since we're talking optimization, the optimget function is another overhead hog, taking about 10% of the remaining run time! But maybe I'll start a separate thread for that one.
Best Answer