Huge performance loss in R2011b with cell based indexing and reassignment of struct field
3 views (last 30 days)
Show older comments
Hi,
In R2011b when you re-assign a field of a struct and index using a cell expansion (indexes{:}), Matlab behaves as if accel is off. It also appears that Matlab is touching all of the pages of the underlying data and this is especially apparent when the underlying data is memory mapped.
It seems like the copy on write mechanism is incorrectly being activated and the data is being copied before the field is reassigned, as if I am attempting to mutate something that already has a reference (see test #7). I have attached a working example and results on R2011a and R2011b (specific versions included in output).
Is this a known problem? I was unable to find any reference to this.
Please note that the performance on R2011a is clean for all tests (including accel off) but R2011b clearly underperforms.
Note: Run the test a few times to produce the below results. In general, the results will be right in terms of what I am trying to demonstrate but the JIT will need to get warmed up to get consistent results (Thanks Jan Simon).
R2011a (expected performance):
----ACCEL ON---- (7.12.0.635 (R2011a) - GLNXA64)
----Iteration 1----
#1: 0.000020
#2: 0.000027
#3: 0.000018
#4: 0.000012
#5: 0.000087
#6: 0.000015
#7: 0.032089
----ACCEL OFF---- (7.12.0.635 (R2011a) - GLNXA64)
----Iteration 1----
#1: 0.000021
#2: 0.000015
#3: 0.000015
#4: 0.000008
#5: 0.000084
#6: 0.000016
#7: 0.032500
R2011b (underperformance on #5 & #6 and with accel off).
----ACCEL ON---- (7.13.0.564 (R2011b) - GLNXA64)
----Iteration 1----
#1: 0.000027
#2: 0.000038
#3: 0.000029
#4: 0.000019
#5: 0.037336
#6: 0.037215
#7: 0.034041
----ACCEL OFF---- (7.13.0.564 (R2011b) - GLNXA64)
----Iteration 1----
#1: 0.036203
#2: 0.036536
#3: 0.036511
#4: 0.035887
#5: 0.036641
#6: 0.036468
#7: 0.032923
Test code:
function slowtest()
z.data = randn(10, 1e6);
fprintf('\n----ACCEL ON---- (%s - %s)\n', version(), computer());
feature('accel', 'on');
slowtest_index(z);
fprintf('\n----ACCEL OFF---- (%s - %s)\n', version(), computer());
feature('accel', 'off');
slowtest_index(z);
end
function slowtest_index(input)
for i=1:1
idxs = {[1]};
fprintf('\t----Iteration %d----\n', i);
t=tic();
a = input;
a.data = a.data([1]);
fprintf('\t\t#1: %f\n', toc(t));
t=tic();
a = input;
d = a.data(idxs{:});
a.data = d;
fprintf('\t\t#2: %f\n', toc(t));
t=tic();
a = input;
d = a.data(idxs{1});
a.data = d;
fprintf('\t\t#3: %f\n', toc(t));
t=tic();
a = input;
a.data = 1;
fprintf('\t\t#4: %f\n', toc(t));
t=tic();
a = input;
a.data = subsref(a.data, substruct('()', idxs));
fprintf('\t\t#5: %f\n', toc(t));
t=tic();
a = input;
a.data = a.data(idxs{:});
fprintf('\t\t#6: %f\n', toc(t));
t=tic();
a = input;
a.data(1) = a.data(2);
fprintf('\t\t#7: %f\n', toc(t));
end
fprintf('\n');
end
6 Comments
Accepted Answer
More Answers (1)
Jan
on 1 Oct 2011
Matlab 2011b, Win7, Core2Duo:
----ACCEL ON---- (7.13.0.564 (R2011b) - PCWIN64)
----Iteration 1----
#1: 0.000029
#2: 0.000033
#3: 0.000021
#4: 0.000012
#5: 0.076800
#6: 0.083983
#7: 0.069058
----ACCEL OFF---- (7.13.0.564 (R2011b) - PCWIN64)
----Iteration 1----
#1: 0.083822
#2: 0.086834
#3: 0.077840
#4: 0.077228
#5: 0.077171
#6: 0.081455
#7: 0.073255
See Also
Categories
Find more on Bessel functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!