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:
function value = get.error(obj) value = obj.error; end
Now, seeing as this code is completely redundant, I decided to delete the get function all together, but this leads to an incredible slowdown in one section of my code where the 'error' property is accessed repeatedly.
In this section of code, the profiler doesn't explicitly say 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.
Why would deleting this useless get function slow down my code?
EDIT: I've isolated the problem enough to post some code samples.
Here's a dummy version of the method call that has the problem:
Here's the code profile without the useless getter:
and with the magical useless getter:
Note that the requires for the performance appear to be as follows:
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.
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)
EDIT 2:
Here's the full pool class; perhaps it'll help:
classdef pool < 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 > 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