Bug 21375

Summary: Dictionary<GUID, float> uses more memory with Mono vs .NET
Product: [Mono] Class Libraries Reporter: John Miller [MSFT] <john.miller>
Component: mscorlibAssignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: adam.kapos, masafa, mono-bugs+mono, mono-bugs+runtime
Priority: ---    
Version: 3.4.0   
Target Milestone: Untriaged   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

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
    XI 7.2.5.5
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:
http://imgur.com/v07Z6Zq
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 3.12.0.76 (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.