Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

IL2CPP 15x slower than MONO, simple Dictionary Test

Discussion in 'iOS and tvOS' started by vqt123, Jun 27, 2015.

  1. vqt123

    vqt123

    Joined:
    Apr 16, 2013
    Posts:
    23
    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
     
    Last edited: Jun 27, 2015
    elias_t and MrEsquire like this.
  2. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    Strange. This should be reviewed and answered by IL2CPP team.
     
  3. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    How about generated cpp codes?
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,779
    @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.
     
  5. vqt123

    vqt123

    Joined:
    Apr 16, 2013
    Posts:
    23
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,779