Optimization of Band Math Image Filter (from 60M cycles to 40M cycles)
Mantis Issue 1041, reported by lhermitte, assigned to rkanavath, created: 2015-05-04
Useless computations were done in OTB 3.16.
Here is a patch that makes the use of Band Math Image Filter goes down from 60M cycles 40M cycles (measured by callgrind on a program compiled with -O2 -g -DNDEBUG)
The ideas behind the optimizations are:
- std::vector::at() shall be avoided. Always. at() is about defensive programming: when the developer is not sure about the indices to be used to access elements in an array, at() may have a sense (a very disputable one as it won't help to report meaningful error messages). std::vector::operator[] is to be preferred every time -- and range checking must be done long before accessing elements.
Note: std::vector::at() is used in other places in OTB code. It shall be hunted down and replaced with the proper function call.
- Access to some same elements were done again and again. Those elements have been factorized out of loops where they are stable.
1431526568 - rashadkmpatch applied on OTB 4.5 and all test with BandMath are passing.
Thanks
1431527288 - rashadkmpatch pushed for OTB 4.5 - waiting for a next dashboard submission.
1431527546 - rashadkmhttp://hg.orfeo-toolbox.org/OTB/rev/803a713b5382
1431528531 - grizonnetmFYI, I've applied a similar patch in BandMath filter which use MuParserX (called in ThreadedGenerateData for every pixel):
http://hg.orfeo-toolbox.org/OTB/rev/c486eb924abe
As Luc said std::vector::at() is used in many other places in OTB code.
1432025996 - julienDashboard seems clear. Closing.