IL2CPP 15x slower than MONO, simple Dictionary Test

Unity version 4.6.6f2

Because of boxing, il2cpp runs 15x slower than MONO when using dictionaries.

Simple test

Initialize a dictionary

private Dictionary<int, int> d1 = new Dictionary<int, int>();

for(inti = 0; i < 1000; i++)
{
d1 = i;
}
put this in an update loop
void Update()
{
F1();
}
private int F1()
{
int accum = 0;
for(inti = 0 ; i < d1.Count - 1; i++)
{
accum += d1[i];
}
return accum;
}
make 2 builds, 1 for mono, one for IL2cpp (Be sure to set il2cpp in xcode to release mode)
use time profiler in instruments to see that il2cpp is 15x slower due to boxing
You can speed things up by 4x by providing a custom IEqualityComparer but it’s still like 5x slower
How the heck do we stop the boxing of the value types!!! How is everyone not noticing this? HashSets, Lists, SortedLists… basically all generic containers are super slow under il2cpp

2 Likes

Strange. This should be reviewed and answered by IL2CPP team.

How about generated cpp codes?

@vqt123

Would you mind submitting a bug report for this issue? We would like to investigate it. The IL2CPP scripting backend should not be boxing value types any more than necessary.

http://fogbugz.unity3d.com/default.asp?708137_34ubgkodituhqrn8

@vqt123

Thanks, we will investigate this.