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

Unity 5 / Xcode 7 / 64-Bit IL2CPP compile times are killing me

Discussion in 'iOS and tvOS' started by Mark-Sweeney, Sep 26, 2015.

  1. Mark-Sweeney

    Mark-Sweeney

    Joined:
    Feb 21, 2010
    Posts:
    172
    It seems ridiculous that a Universal "hello world" using Unity GUI creates a 705 MB Xcode project that takes almost 6 1/2 minutes to compile and install on my iPad or iPhone from my Mac Mini server.

    I have apps I've been trying to update for the app store to 64-bit (Universal), but they never, ever finish compiling in Xcode 6 or 7.

    Xcode doesn't crash, hang or freeze - I can hit the stop button and it will stop compiling. But it never finishes a build or archive, even after running for 90 minutes. There's no error messages - over 200 warnings.

    Have tried with Unity 5.1, 5.2 the latest patch update, Xcode 6, 7, 7.1, Yosemite, El Capitan, and two difference macs. I get the same result - projects that never finish compiling.

    If I set the scripting backend to Mono2x the apps compile and install like normal, but that's now help since 64-bit builds are required.
    I have no idea what to do or how to get these apps to build and compile properly. Ready to throw Unity out and start from scratch with Unreal.
     
    Last edited: Sep 26, 2015
  2. Mark-Sweeney

    Mark-Sweeney

    Joined:
    Feb 21, 2010
    Posts:
    172
    I tried leaving it running with powersaver preferences turned off. It only took 2 hours and 27 minutes for a Universal IL2CPP build to compile in Xcode.

    Yeah. 2 hours 27 minutes using IL2CPP Scripting backend.

    Using Mono2X, it takes two minutes.

    IL2CPP Scripting backend takes 7,350% longer to compile in Xcode than Mono2x.
     
    Last edited: Sep 26, 2015
  3. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @Mark Sweeney

    If possible, could we have a look at your project in a bug report? The IL2CPP scripting backend compile times are certainly longer than the Mono scripting backend, but this seems like far too great a difference.
     
  4. Mark-Sweeney

    Mark-Sweeney

    Joined:
    Feb 21, 2010
    Posts:
    172
    I filed the bug report yesterday Josh, and included a zip with the entire project composed inside. I'm still not having any luck getting IL2CPP backend script to compile in Xcode in a reasonable time.
    Bug report/Case No. 732782
     
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @Mark Sweeney

    Thanks, I appreciate it! We will have a look at this project.
     
  6. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,021
    How much ram does your mac mini have? I found ram made a much MUCH bigger difference with building times than I thought it would with mine. (although mine was memory starved at 4GB, so I guess that's why there was such a big difference).
     
  7. Mark-Sweeney

    Mark-Sweeney

    Joined:
    Feb 21, 2010
    Posts:
    172
    My Mac Mini Server has 8 GB RAM (using it as a mac, not as a server).

    My wife's brand new iMac also has 8GB RAM, and that took 1 hour 40 minutes to compile from Xcode.

    If I do it with Mono2X scripting backend, it takes about 2 1/2 minutes.

    I've been trying to figure it out and not having any luck. Even a basic "Hello World" with just text, using Unity UI took over 5 minutes to compile and install. No scripts, 3D or images of any kind.

    Maybe I missed some setting or something that causes these long compile times.
     
  8. Mark-Sweeney

    Mark-Sweeney

    Joined:
    Feb 21, 2010
    Posts:
    172
    I don't know if you've had any luck figuring this out, but Changing Optimization Level in the Building Setting in Xcode to 'None [-Oo]' reduces the compile/install time to 12 minutes and 15 seconds instead of 2 1/2 hours. (6.5 minutes for Xcode to compile, the rest for Linking, generate dYSM, signing and installing).

    I got that idea from this thread:

    http://answers.unity3d.com/questions/969870/too-slow-to-compile-archive-in-xcode-il2cpp.html
     
    Deleted User likes this.
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @Mark Sweeney

    No, we've not yet investigated this issue, sorry. I'm glad that you've found something of a work around, although we still need to determine the cause of the issue, as it is probably not feasible to ship with optimizations turned off. I'll ping our QA team to check their progress on this issue.
     
  10. Deleted User

    Deleted User

    Guest

    I have the same problem with archive. It worked once when i started it over Night but that is way to long !
     
  11. Deleted User

    Deleted User

    Guest

    It worked with the tip of changing the Optimization level to None . Great , Thank you !
     
    laphil likes this.
  12. Mark-Sweeney

    Mark-Sweeney

    Joined:
    Feb 21, 2010
    Posts:
    172
    It's good for testing on a device, but it's still a pain to have to let it compile overnight for uploading to iTunes.
     
  13. Mark-Sweeney

    Mark-Sweeney

    Joined:
    Feb 21, 2010
    Posts:
    172
    I'm going to have to submit another bug report. I have a brand new 27" iMac. Last night, a new build took over 3 hours for Xcode to archive.

    I wonder if it has anything to do with Unity abandoning Unityscript, which is what is used in this 5 year old app I'm trying to update.
     
  14. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @Mark Sweeney

    Unity Script might be the issue here. At least, the Unity Script compiler often generates different IL than the C# compiler, so maybe IL2CPP is converting that IL to C++ in some sub-optimal way. Is this the same project you submitted with bug 732782? If so, then there is no need to submit a bug report again.
     
  15. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Just wanted to confirm that compiling IL2CPP takes approx. 7x longer than Mono.
     
  16. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @Cascho01

    The difference will depend on your specific project, but that is not surprising. We're working to improve build times now, though. At the moment it should be possible to do incremental builds with IL2CPP on iOS. So Xcode will only compile the changed C++ files. In the latest releases of Unity, we've changed IL2CPP to generate C++ code that is more stable - that is, small changes to managed code will lead to small changes to the generated C++ code.
     
  17. Mark-Sweeney

    Mark-Sweeney

    Joined:
    Feb 21, 2010
    Posts:
    172
    It's the same app, but I've made a ton of changes and optimizations, and removed all extraneous files. Going to see if it uploads to iTunes connect properly - last time it said I couldn't use beta software or SDKs - which I wasn't.
     
  18. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @Mark Sweeney

    Thanks. There is no need to submit another bug report then. I'll see if we can look at your previous one finally.
     
  19. laphil

    laphil

    Joined:
    Mar 20, 2013
    Posts:
    1
    I've been having the same problem for a while after upgrading Xcode 7.3 and El Capitan that compiling just would not complete. I am so grateful for the tip to set the Optimization level to None for Release! Thank you for the help, much appreciated!
     
  20. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    @laphil

    You probably don't want to ship with optimization disabled. It might be better to determine why the build is taking so long. In some other cases we have seen where the build seems to hang, we have lots of local variables and allocations happen in one huge method (maybe 10,000 or more). This usually occurs when data tables of some sort are encoded into script code.

    Often you can improve the compile and runtime performance of this code by encoding the data in some serialized format and loading it as runtime.
     
  21. Mark-Sweeney

    Mark-Sweeney

    Joined:
    Feb 21, 2010
    Posts:
    172
    Do you have Code with arrays in them, such as,

    private var VR10 = Array(0,1,2,3,4,5,6,7);

    This was causing the problem for me. (My arrays were much longer). Changing it to:

    private var VR10 = [0,1,2,3,4,5,6,7];

    solved my problems.

    Now compiling for Xcode only takes a couple of minutes.
     
  22. SweatyChair

    SweatyChair

    Joined:
    Feb 15, 2016
    Posts:
    140
    We have the same problem but we are using C#....

    This happened after we integrated ARKit, I checked all our code and there's nothing about using Array()....

    Any idea?

    Using:
    Unity 5.6.3
    XCode 9
     
    Last edited: Oct 6, 2017
  23. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Compile times take a long time if you have a lot of code, so some things to check:
    • Are you using a lot of generics with many different generic type arguments? This can generate a lot of code.
    • Source files that are not referenced anywhere but are still in your project will be compiled, so check that you have removed all example scripts, unused scripts etc from your project (or move them into an excluded folder).
    Also this doesn't really solve the problem but maybe it helps you: I sell Hdg Remote Debug on the asset store which can be used to tweak fields on GameObjects live on your running device. That way you don't have continually re-deploy if you just want to iterate on some small things.

    -sam
     
  24. lostplesed

    lostplesed

    Joined:
    Mar 26, 2014
    Posts:
    25
    i have the same problem

    clang: error: unable to execute command: Killed: 9
    clang: error: clang frontend command failed due to signal (use -v to see invocation)
    Apple LLVM version 9.0.0 (clang-900.0.39.2)
    Target: arm-apple-darwin16.7.0
    Thread model: posix
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
    clang: note: diagnostic msg: PLEASE submit a bug report to http://developer.apple.com/bugreporter/ and include the crash backtrace, preprocessed source, and associated run script.
    clang: note: diagnostic msg:
    ********************

    PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
    Preprocessed source(s) and associated run script(s) are located at:
    clang: note: diagnostic msg: /var/folders/01/h2b2_63n7wj4xw4phrn78sp80000gn/T/Bulk_Assembly-CSharp_8-0dd90c.cpp
    clang: note: diagnostic msg: /var/folders/01/h2b2_63n7wj4xw4phrn78sp80000gn/T/Bulk_Assembly-CSharp_8-0dd90c.sh
    clang: note: diagnostic msg: Crash backtrace is located in
    clang: note: diagnostic msg: /Users/lx/Library/Logs/DiagnosticReports/clang_<YYYY-MM-DD-HHMMSS>_<hostname>.crash
    clang: note: diagnostic msg: (choose the .crash file that corresponds to your crash)
    clang: note: diagnostic msg:

    ********************
    Bulk_Assembly-CSharp_8.cpp is 8m
    clang crash after i found out it eaten 30g memory of my mac, anyone solve this problem?
    xcode 9.2
    unity5.5.2f1
     
  25. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    We've had problems compiling methods that have many (> 5000) local variables. Is there anything like that in Bulk_Assembly-CSharp_8.cpp? This can happen if you have a large number of local variables in the associated C# code.

    Outside of that, we've not had many problems compiling with Xcode. You also may want to try a newer version of Unity if that is possible.
     
  26. lostplesed

    lostplesed

    Joined:
    Mar 26, 2014
    Posts:
    25
    thanks for help, i had found out the problem. with c# code
    Code (CSharp):
    1. public class SomeWord
    2. {
    3.     public static List<string> Words = new List<string>(new string[]
    4.     {
    5.         "aaa"
    6.         , "bbb"
    7.         , "ccc"
    8.         , "ddd"
    9.         , "eee"
    10.         , "fff"
    11.         , "ggg"
    12.         // the list has 3w ele
    il2cpp convert this to

    Code (CSharp):
    1. extern "C"  void SomeWord__cctor_m3830774958 (Il2CppObject * __this /* static, unused */, const MethodInfo* method)
    2. {
    3.     static bool s_Il2CppMethodInitialized;
    4.     if (!s_Il2CppMethodInitialized)
    5.     {
    6.         il2cpp_codegen_initialize_method (SomeWord__cctor_m3830774958_MetadataUsageId);
    7.         s_Il2CppMethodInitialized = true;
    8.     }
    9.     {
    10.         StringU5BU5D_t1642385972* L_0 = ((StringU5BU5D_t1642385972*)SZArrayNew(StringU5BU5D_t1642385972_il2cpp_TypeInfo_var, (uint32_t)((int32_t)26109)));
    11.         NullCheck(L_0);
    12.         ArrayElementTypeCheck (L_0, _stringLiteral1002530778);
    13.         (L_0)->SetAt(static_cast<il2cpp_array_size_t>(0), (String_t*)_stringLiteral1002530778);
    14.         StringU5BU5D_t1642385972* L_1 = L_0;
    15.         NullCheck(L_1);
    16.         ArrayElementTypeCheck (L_1, _stringLiteral632527236);
    17.         (L_1)->SetAt(static_cast<il2cpp_array_size_t>(1), (String_t*)_stringLiteral632527236);
    18.         StringU5BU5D_t1642385972* L_2 = L_1;
    19.         NullCheck(L_2);
    20.         ArrayElementTypeCheck (L_2, _stringLiteral1347057182);
    21.         (L_2)->SetAt(static_cast<il2cpp_array_size_t>(2), (String_t*)_stringLiteral1347057182);
    22.         StringU5BU5D_t1642385972* L_3 = L_2;
    23.         NullCheck(L_3);
    24.         ArrayElementTypeCheck (L_3, _stringLiteral2523984302);
    25.         (L_3)->SetAt(static_cast<il2cpp_array_size_t>(3), (String_t*)_stringLiteral2523984302);
    26.         StringU5BU5D_t1642385972* L_4 = L_3;
    27.         NullCheck(L_4);
    28.         ArrayElementTypeCheck (L_4, _stringLiteral2530099938);
    29.         (L_4)->SetAt(static_cast<il2cpp_array_size_t>(4), (String_t*)_stringLiteral2530099938);
    30.         StringU5BU5D_t1642385972* L_5 = L_4;
    31.         NullCheck(L_5);
    32.                // this style of code repeat nearly 3w times
    just pick out the string in list and put it in a file, then read in from file solve the problem. the c# code is auto generate with some reason maybe i don't know why. next time if someone meet the same problem, do with this step:
    1) check out the xcode compile step and find out which file cost a lot of time
    2) open the file and find if there is some weird function with a lot of statement in
    3) find out which c# file convert to those code and change it

    sorry about my poor english i wish can help you.
     
  27. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    This is indeed the kind of thing that causes problems. All of those local variables in the C++ code make the register allocation pass in the C++ compiler rather difficult.

    I would recommend storing the information in the list in a separate data file, then iterating over the data file contents in the C# code to create the C# object you need which holds the data.
     
  28. lostplesed

    lostplesed

    Joined:
    Mar 26, 2014
    Posts:
    25
    thanks
     
  29. pintianz

    pintianz

    Joined:
    Mar 1, 2015
    Posts:
    25
    I'm suffering with this issue it seems. But what if my large dictionary object include inline functions? I don't think I can easily parse that from an external file and even if I do, won't parsing that stuff during run-time be super slow since there is so much variable references? Please help I have ~3000 scenarios. I'm building a project from Unity 2018.2.9 to xcode 9.4.1.

    Code (CSharp):
    1. {1, new ScenarioNode("PASSAGE TEXT 1 HERE. Took out due to spoilers.",
    2. //***display condition for choices
    3. new Func<bool>[]    {()=>{return true;}},
    4. //***display text for choices
    5. new Func<string>[]      {()=>{ return "...";}},
    6. //***linked scenario ID for choices
    7. new int[]       {-1},
    8. //***various actions or subroutine to run base on choices if any
    9. new Action[]        {()=>{GameController.controller.GenerateWorld(CityEnum.Location_Tutorial_Start);}})},
    10. {2, new ScenarioNode("PASSAGE 2 TEXT HERE.",
    11. new Func<bool>[]    {()=>{return true;}},
    12. new Func<string>[]      {()=>{ return "...";}},
    13. new int[]       {2366},
    14. new Action[]        {()=>{}})},
    15. {3, new ScenarioNode("PASSAGE 3 TEXT HERE.",
    16. new Func<bool>[]    {()=>{return true;}},
    17. new Func<string>[]      {()=>{ return "Eat food";}},
    18. new int[]       {-1},
    19. new Action[]        {()=>{GameController.controller.GenerateItemPage(true, false, 4);}})},
    20. ...
    21. ...
    22. ... so on so forth
     
  30. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    I can't speak to your specific situation without profiling data and a better understanding of the code. I does look like this code has a good bit of "hidden" cost at runtime though. Each of those delegate will require at least one heap allocation, for example. It might be worth writing a synthetic benchmark outside of your project to verify the runtime cost of moving this a data file that is loaded into memory once.
     
  31. pintianz

    pintianz

    Joined:
    Mar 1, 2015
    Posts:
    25
    Wow I didn't think you'd reply given the age of this post, thanks. I'd be glad to write my static dictionary into a external file. Having the project compile is more important than performance right now.

    However I'm not sure how to do it. Can you point me to the right direction where I can learn how to move my static dictionary to an external data file and have it loaded into memory once? Also can you suggest where I can learn more about writing a synthetic benchmark to gauge run-time performance for this issue?

    A side question: My mac is super old (mid 2010 mac book pro with almost maxed out disk usage and 4 GB of ram). Compile is super slow, do you think xcode can brute force its way out of this issue if I upgrade to 8GB of ram and add more storage.

    Here is the declaration of the variable if it helps any. I could also message you the script.


    Code (CSharp):
    1. private static Dictionary<int, ScenarioNode> scenarioDict =
    2.         new Dictionary<int, ScenarioNode>
    3.     {
    4.         {1, new ScenarioNode("PASSAGE TEXT 1",
    5. new Func<bool>[]    {()=>{return true;}},
    6. new Func<string>[]      {()=>{ return "...";}},
    7. new int[]       {-1},
    8. new Action[]        {()=>{GameController.controller.GenerateWorld(CityEnum.Location_Tutorial_Start);}})},
    9. {2, new ScenarioNode("PASSAGE TEXT 2",
    10. new Func<bool>[]    {()=>{return true;}},
    11. new Func<string>[]      {()=>{ return "...";}},
    12. new int[]       {2366},
    13. new Action[]        {()=>{}})},
    14. {3, new ScenarioNode("PASSAGE TEXT 3",
    15. new Func<bool>[]    {()=>{return true;}},
    16. new Func<string>[]      {()=>{ return "Eat food";}},
    17. new int[]       {-1},
    18. new Action[]        {()=>{GameController.controller.GenerateItemPage(true, false, 4);}})},
    19. {4, new ScenarioNode("PASSAGE TEXT 4",
    20. new Func<bool>[]    {()=>{return true;}},
    21. new Func<string>[]      {()=>{ return "...";}},
    22. new int[]       {5},
    23. new Action[]        {()=>{}})},
    24. .....}
     
  32. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,775
    You'll need to think about what a ScenarioNode is. It looks to be something like this:

    Code (CSharp):
    1. class ScenarioNode
    2. {
    3.     public string Name;
    4.     public bool Enabled;
    5.     public string Message;
    6.     public int[] Values;
    7.     public Action Behavior;
    8. }
    The first four fields could all be serialized to something like JSON, then you could use a JSON reader to load that file into an in-memory data structure. I don't know about the last field - it seems to be a function. You can serialize that easily, but you could have a array of functions elsewhere, then serialize an index into that array. I'm just guessing though.

    Regarding writing benchmarks, I'd start with Benchmark .NET: https://benchmarkdotnet.org - it is a great tool.