Huge performance loss in R2011b with cell based indexing and reassignment of struct field
Mostra commenti meno recenti
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 Commenti
Jan
il 1 Ott 2011
Is the table correct?
R2011a (expected performance):
----ACCEL ON---- (7.12.0.635 (R2011a) - GLNXA64)
#1: 0.000264
----ACCEL OFF---- (7.12.0.635 (R2011a) - GLNXA64)
#1: 0.000022
Why is the function much faster with disabled acceleration?
Nathan
il 1 Ott 2011
Nathan
il 1 Ott 2011
Daniel Shub
il 1 Ott 2011
Have you tried it without "5", the one with subsref. I wonder if MATLAB is doing some sort of garbage collection after the call. I don't have MATLAB access right now to check.
Nathan
il 1 Ott 2011
Nathan
il 1 Ott 2011
Risposta accettata
Più risposte (1)
Jan
il 1 Ott 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
1 Commento
Nathan
il 2 Ott 2011
Categorie
Scopri di più su Bessel functions in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!