Bug 6697 - Slow performance of parallel processes using Linq and external support classes
Summary: Slow performance of parallel processes using Linq and external support classes
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-08-27 05:03 UTC by MardyGit
Modified: 2012-08-28 10:13 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description MardyGit 2012-08-27 05:03:59 UTC
I have a library which performs various calculations on byte array data, using Parallel.For for the outer loop. The data is serial and represents a matrix of ~300x300x4 bytes in its iOS / iPhone / iPad incarnation, but has been tested on much larger matrixes in Windows, where the library originates. The problem manifests itself in the emulator and in hardware, debug and release. Some of the classes calculate inline and have no performance issues. Those which use lightweight support classes perform much, much more slowly when parallized than when made to operate on a single thread. These typically use one or more support objects per byte group. Static methods of these support classes do not have performance issues. This performance issue also manifests itself when using Linq to determine things like highest, lowest, median and average values of sampled data. When some of these library classes were changed to calculate results manually, inline, they became fully performant. The support classes are self-contained, safe and do not use unmanaged resources – they are just intermediate difficulty math.

Below is pretty much how every loop is structured…

            Parallel.For(0, iBound, i =>

                for (int j = 0; j < jBound; j++)
                    //Do something to the byte data

Really not very complex, the only additional complication is that is runs on a background thread.
Comment 1 MardyGit 2012-08-28 10:13:55 UTC

Problem is iOS garbage collection. Furious reworking to make whatever I couldn't inline be instantiated once per thread gets around this.