Bug 21375 - Dictionary<GUID, float> uses more memory with Mono vs .NET
Summary: Dictionary<GUID, float> uses more memory with Mono vs .NET
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 3.4.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2014-07-16 14:13 UTC by John Miller [MSFT]
Modified: 2015-02-07 19:15 UTC (History)
4 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 GitHub or Developer Community 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 John Miller [MSFT] 2014-07-16 14:13:56 UTC
### Overview: 

    We have observed a strange behavior while developing for iOS. Creating empty dictionaries results in a huge memory usage, something that does not happen on Windows platforms. For example creating 60000 Guid-float dictionaries result in 30MB memory usage, which is a critical amount on a mobile platform. The same takes up 800kb of memory in a Windows 8.1 Store app.

### Steps to Reproduce: 

>Dictionary<Guid, float>[] dicts = new Dictionary<Guid, float>[50000];
>for (int i = 0; i < 50000; i++)
>    dicts[i] = new Dictionary<Guid, float>(0);

    It appears that unlike CLR, Mono initializes the dictionary with a size of 12, which results in an additional size of 12*(16+8) per dictionary.

### Actual Results: 

    ~30 MB of memory used on iOS

### Expected Results: 

    Similar memory profile as shown on Windows (~800 kb)

### Build Date & Platform: 

    Mono 3.4
Comment 2 Marek Safar 2014-07-21 14:35:34 UTC
Fixed in master
Comment 4 Marek Safar 2014-07-23 13:21:50 UTC
Mono after 3.6
Comment 5 Adam Kapos 2015-02-06 16:43:51 UTC
It still allocates an array with the size of 1. Microsoft's implementation doesn't allocate the array at all:
Comment 6 Mikayla Hutchinson [MSFT] 2015-02-06 20:01:57 UTC
@Adam: we're now using Microsoft's implementation of Dictionary<T>: https://github.com/mono/mono/commit/346894957c49a9c839236e0fc0296e4e3d44e10b
Comment 7 Adam Kapos 2015-02-06 20:11:06 UTC
Oh, you cannot possibly imagine how happy I am to hear that :)

Is it part of MDK (the latest on the alpha channel)? If not, any estimates when this will hit the alpha channel?
Comment 8 Mikayla Hutchinson [MSFT] 2015-02-07 19:15:57 UTC
It's not in 3.12. I imagine it'll be in 3.14, though I don't have an ETA for that.