Bug 37846 - ConcurrectDictionary is 100x slower
Summary: ConcurrectDictionary is 100x slower
Alias: None
Product: iOS
Classification: Xamarin
Component: Mono runtime / AOT compiler ()
Version: XI 9.2
Hardware: PC Mac OS
: Normal normal
Target Milestone: C6SR2
Assignee: Zoltan Varga
Depends on:
Blocks: 37783
  Show dependency tree
Reported: 2016-01-20 18:07 UTC by Rolf Bjarne Kvinge [MSFT]
Modified: 2016-03-03 17:26 UTC (History)
8 users (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 Rolf Bjarne Kvinge [MSFT] 2016-01-20 18:07:30 UTC
Test case:
* https://github.com/rolfbjarne/TestApp - branch: bug37783 

* Run on device.


mtouch (monotouch-9.1.0-branch: bae2cdb)

> Running ConcurrentDictionary test...
> Added in 10ms
> Fetched 100000 existing in 9ms
> Fetched 100000 non-existing in 8ms
> ----
> Running Dictionary test...
> Added in 1ms
> Fetched 10000000 existing in 737ms
> Fetched 10000000 non-existing in 632ms
> ----

mtouch (cycle6-xi: b82c335)

> Running ConcurrentDictionary test...
> Added in 103ms
> Fetched 100000 existing in 1156ms
> Fetched 100000 non-existing in 1138ms
> ----
> Running Dictionary test...
> Added in 8ms
> Fetched 10000000 existing in 11273ms
> Fetched 10000000 non-existing in 10464ms
> ----

mtouch master (e6e5d94034420925c40e298971836eed031904dd)

> Running ConcurrentDictionary test...
> Added in 84ms
> Fetched 100000 existing in 1078ms
> Fetched 100000 non-existing in 1057ms
> ----
> Running Dictionary test...
> Added in 3ms
> Fetched 10000000 existing in 1808ms
> Fetched 10000000 non-existing in 1372ms
> ----

ConcurrectDictionary is 100x slower (1s vs 10ms) in master than in 9.1.0
Dictionary is 2.5x slower (1.8s vs 0.7s) in master than in 9.1.0 (interestingly Dictionary was 15x slower in 9.2.1, but that seems to be fixed).

An instruments trace seems to indicate this is AOT related: https://www.dropbox.com/s/vxe9cd0oj2gqj5v/Screenshot%202016-01-20%2019.05.54.png?dl=0 (also I have not been able to reproduce this slowdown in the simulator).
Comment 2 Zoltan Varga 2016-01-21 17:52:06 UTC
This is caused by the partial sharing changes, i.e. List<int> is now shared with List<AnEnum> for example.
Comment 3 Zoltan Varga 2016-01-21 19:32:03 UTC
The ConcurrentDictionary slowdown should be fixed by mono 7003343902d700e5f2770dc367be18876d163e50.

As for the dictionary slowdown, its somewhat expected, gshared code is slower than non-gshared code. Will seem what more can be done there.
Comment 4 Zoltan Varga 2016-01-21 20:57:08 UTC
The slowdown on dictionary doesn't look easily fixable without disabling sharing or a significant rewrite of the generic sharing code.
Comment 5 Rolf Bjarne Kvinge [MSFT] 2016-01-22 08:29:41 UTC
@Zoltan, I've filed bug #37894 for the dictionary slowdown, since it seems like a separate issue, and I'm closing this bug considering it's about ConcurrentDictionary only.

And is this something that can be backported to C6?
Comment 6 Zoltan Varga 2016-01-22 13:18:11 UTC
Comment 8 Zoltan Varga 2016-01-22 17:09:42 UTC
The backport is on this branch:
Comment 9 Rolf Bjarne Kvinge [MSFT] 2016-01-22 17:44:15 UTC
Comment 11 Sebastien Pouliot 2016-02-26 22:36:08 UTC
cherrypick in mono/mono-4.2.0-branch 097695ae35f9c684d79a900078e878542e69167b

maccore/cycle6-xi bumped in e32859df16b0444e2eb26a1bd4eb47f4a0b540c8
Comment 12 Rajneesh Kumar 2016-03-03 17:26:31 UTC
I have checked this issue with C6SR2 build: 
and observed that the current ConcurrentDictionary test... is 17 ms.

Screencast: http://www.screencast.com/t/oBxNAo5olz0

This issue has been fixed and working as expected, hence I closing this issue.


Environment Info: https://gist.github.com/saurabh360/36ff40b7178a2eca6534
Application Output: https://gist.github.com/saurabh360/3e3394fb51c8dbb7d325