Note that there are some explanatory texts on larger screens.

plurals
  1. POMatlab Get Property function causing performance problems
    text
    copied!<p>I have a property in one of the classes I created that currently has an unnecessary get function associated with it. I initially made it to do useful things before returning the value, but now I just need the property value, so the get function has been reduced to this:</p> <blockquote> <pre><code> function value = get.error(obj) value = obj.error; end </code></pre> </blockquote> <p>Now, seeing as this code is completely redundant, I decided to delete the get function all together, but this leads to an <em>incredible</em> slowdown in one section of my code where the 'error' property is accessed repeatedly.</p> <p>In this section of code, the profiler doesn't <em>explicitly say</em> that the missing get function is the cause of the problem (it says all of the time is wasted at the 'end' of a 'for' loop), but when I add the functionally useless code back in, the performance problem goes away.</p> <p>Why would deleting this useless get function slow down my code?</p> <p>EDIT: I've isolated the problem enough to post some code samples.</p> <p>Here's a dummy version of the method call that has the problem: <img src="https://i.stack.imgur.com/hv2Cp.png" alt="enter image description here"></p> <p>Here's the code profile without the useless getter: <img src="https://i.stack.imgur.com/a6Rto.png" alt="enter image description here"></p> <p>and with the magical useless getter: <img src="https://i.stack.imgur.com/ASOhp.png" alt="enter image description here"></p> <p>Note that the requires for the performance appear to be as follows:</p> <ol> <li><p>use some property of my 'pool' object in a computation set to any variable. The 'error' property is the one that caught my attention, but the bug happens with all properties in the same situation.</p></li> <li><p>the computation involves anything, even '.* 0' causes this slowdown, but a single term being set is slowdown free (e.g. obj.pools(i).delta = obj.pools(i).error)</p></li> </ol> <p>EDIT 2:</p> <p>Here's the full pool class; perhaps it'll help:</p> <pre><code>classdef pool &lt; handle properties name; unit_count; activation; net_input = 0; %all projections now incoming projections = []; error; % same is dEd net for rbp target; clamped_error = false; delta; clamped_activation = 0; %0 no clamp, 1 soft clamp, 2 hard clamp copyback = false; copy_from; type = 'hidden'; activation_history; error_history; end methods function obj = pool(name,count,type,copy_from) obj.name = name; assignin('caller', name, obj); obj.unit_count = count; obj.error = zeros(1,count); obj.target = zeros(1,count); obj.delta = zeros(1,count); obj.activation = zeros(1,count); obj.net_input = zeros(1,count); obj.activation_history(:,1) = zeros(1,count); obj.error_history(:,1) = zeros(1,count); if nargin &gt; 2 obj.type = type; if nargin == 4 obj.clamped_activation = 2; obj.activation = ones(1,count)/2; obj.copy_from = copy_from; obj.copyback = true; end else obj.type = 'hidden'; end switch obj.type case 'input' obj.clamped_activation = 2; case 'output' obj.clamped_error = true; case 'bias' obj.clamped_activation = 2; obj.activation = 1; case 'hidden' end end function proj = connect(obj,send_pool,proj_var) %see if you need a new projection or if the user provided one if nargin == 2 proj = projection(obj, send_pool); else proj = proj_var; end obj.projections = [obj.projections struct('from',send_pool,'using',proj)]; end function value = get.error(obj) value = obj.error; end end end </code></pre>
 

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