Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This sounds like Matlab JIT or interpreter weirdness.</p> <p>You may be looking at a Matlab bug related to MCOS memory management, like that discussed in <a href="https://stackoverflow.com/questions/6697951/dataset-array-indexing-very-slow-with-matlab-statistics-toolbox/6698559#6698559">Dataset array indexing is very slow with Statistics Toolbox</a>. That bug looks like it causes spurious deep copying of objects when referencing their fields in some cases. If you have cell arrays or other complex structures in your pool objects, that could cause similar behavior - they get copied in to new variables, and maybe the deallocation cost is showing up at the "end".</p> <p>I was able to reproduce similar surprising slow results in several Matlab versions. But I wasn't able to show any difference from the presence of a getter.</p> <p>File fooclass.m.</p> <pre><code>classdef fooclass properties error = 42; whatever = 42; delta = 1; bigjunk = num2cell(rand(1000,40)); %bigjunk = rand(1000,10000); % non-cell does not cause slowdown end methods % function out = get.error(obj) % out = obj.error; % end end end </code></pre> <p>File looper.m.</p> <pre><code>classdef looper properties pools end methods function obj = looper() obj.pools = repmat(fooclass(), [1 5]);; end function weird(obj) p = obj.pools; n = numel(p); for i = 1:n dummy = obj.pools(i).error .* 0; end end end end </code></pre> <p>To reproduce:</p> <pre><code>&gt;&gt; lp = looper; &gt;&gt; tic; for i = 1:100; weird(lp); end; toc Elapsed time is 0.600428 seconds. </code></pre> <p>That's on my R2011a (prerelease) on 64-bit Windows 7. That's slow. The time is proportional to the size of bigjunk, and the profiler says it almost all happens on the <code>p = obj.pools</code> line. This suggests that the object reference is causing a copy instead of using the copy-on-write optimization like it's supposed to. Or it's walking the object graph, or something. Something similar could be going on with your code.</p> <p>Might be best to just chalk it up to interpreter weirdness, leave the getter in there if it makes your code faster, and wait for a fix in the next release. Sounds worth submitting to MathWorks as a bug report.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload