Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Mono Upgrade Future plans for the Mono runtime upgrade

Discussion in 'Experimental Scripting Previews' started by JoshPeterson, Apr 3, 2017.

  1. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I don't think that we have enough data yet to encourage async/await over coroutines, but that may come in the future. Indeed, making class libraries that can be used across the .NET ecosystem is something that we want to enable though.

    As for System.Numerics, I think that we had some problems related to its implementation, although I don't recall all of the details of that thread.
     
    codestage and npatch like this.
  2. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,166
    You wrong

    Task and async/await is just a conceptual library to Tasking things. It just the default TaskRunner of dotnet library is threading. But you could always override that to single thread runner. You could even change TaskRunner to work under CoRoutine itself if you would like

    You don't understand that Task and CoRoutine is both screwdriver. It is the same and Task is actually more elaborate to the point that is was used in multithread

    If I would make analogy I could said that it is a new screwdriver that could drive multiple screws at the same time. And you just only see it drive 4 screws so you scare that it can only drive 4 screws and cannot drive 1 screw. But it actually can drive any number of screw so 1 is never be a problem
     
  3. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,166
    Nearly 2 months so I wish to ask this again
    Will I could be sure that .NET 4.6 will release with the 2017.1 ?
    I wish it would at least still being experimental flag in 2017.1. But please don't take it out from the actual release
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @Thaina

    Yes, Unity 2017.1 will have support for .NET 4.6, although it is still experimental. We're not planning to turn back now!
     
  5. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,166
    That's great! Now I will go 2017.1 for my project without turning back too
     
  6. j-borden

    j-borden

    Joined:
    Mar 3, 2015
    Posts:
    21
    Hi, checking in again! I downloaded and tried out the new runtime but I was frustrated to find out that it can only load other full .NET framework libraries. I think a few others have run into this problem but packages built based on .NET Standard are unable to be used with Unity3D because they move the responsibility of the runtime to a separate DLL that is not provided with the full profile (i.e. System.Runtime.dll)

    I was able to get things to work by moving all the needed DLLs into the plugins folder of a test project, however (including getting System.Runtime.dll off of Nuget) so if you are facing a similar issue this might help. Has anyone else found a more elegant solution? What I'd really like to do is use Nuget with Unity3D, but that doesn't seem to be easily allowed yet.
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @j-borden

    Indeed, I'm unaware of a better solution for this in Unity 2017.1. Our support for .NET 4.6 only works with the full .NET 4.6 profile (and there are a few missing types there as well). We're working now on support for .Net Standard 2.0, so that you will be able to use an assembly compiled against .Net Standard 2.0 or earlier, or an assembly compile against .NET 4.6. This isn't in a 2017.2 beta release yet, but we're hoping to make it before the 2017.2 release is out (although I can't promise that for sure).
     
  8. j-borden

    j-borden

    Joined:
    Mar 3, 2015
    Posts:
    21
    Thanks for replying so quickly! I'm really looking forward to that. In the meantime I wrote a blog post about what I did to make the library work (i.e. getting stuff manually off of Nuget, taking advantage of multi-framework targeting, moving it into the Unity project and compiling, etc). I can post it here if that's ok, as it might be informative for others, but if not that's fine too (it could be self promoting since it is the product that I work on)
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Go ahead and post it, it might help others!
     
  10. j-borden

    j-borden

    Joined:
    Mar 3, 2015
    Posts:
    21
    Here is the post!
     
  11. j-borden

    j-borden

    Joined:
    Mar 3, 2015
    Posts:
    21
    I'd like to point out some pain I had with this (not specific to Unity3D, but probably applicable). Once you await something, be aware that when you return you are not necessarily on the same thread anymore. In fact you are probably not. That means that if you depend on being on the Unity main thread you WILL find yourself off of it after the await. This is not a problem with Coroutines. By default, though, SynchronizationContext is completely worthless and this would need to be implemented inside of Unity3D itself using a consumer queue. There is no way to inject yourself back into a running thread without that thread knowing about that situation first.

    So don't think that async / await is some magic that will work automatically, it requires orchestration. See this thread for your fate.
     
    MechEthan likes this.
  12. ncgreco

    ncgreco

    Joined:
    Mar 1, 2016
    Posts:
    11
    I have to ask since this is on topic of the Mono Runtime. Is InternalCall open to Unity Game Developers to use to speed up native C++ libraries? Or is that something still exclusive to the Unity Engine?
     
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @ncgreco

    No, InternalCall into the runtime or the engine is not something we support. The API layer between the managed and native code in the runtime or the engine is constantly changing, and not something that we can keep stable.

    With that said, we do have some incredible technology coming that will allow you to right very fast code in C#. Check out this video from Unite Europe 2017 if you are interested:
     
    ncgreco and Alverik like this.
  14. ncgreco

    ncgreco

    Joined:
    Mar 1, 2016
    Posts:
    11
    Thanks, fantastic video!
     
  15. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    @JoshPeterson
    Hey, quick questions:
    1) Ref returns - since they're in c# language version 7, unity won't support them for now, but I feel like that will change soon, right?
    2) What exactly are the performance implications here, specifically I have an scneario in mind:
    getting and modifying all particles in a particle system (right now you have to provide a list or array and unity will copy over all data into your array). That should be a lot more performant using ref-returns, right? Or is the native<>managed transition getting in the way here as usual? If so, what are potential places where ref-returns can really make a difference in Unity?
    3) What is the approximate time-table for supporting c#7 and higher?
    4) Will unity make 100% use of roslyn to compile code, ditching the mono compiler and only using mono for the runtime eventually? (or is that already the case maybe?)
     
  16. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yes, we're working on C# 7 language support now.

    Use ref returns should really help with allocation-free APIs. We will take it slow changing existing APIs so as not to break any working code, but our plan is to move more and more toward APIs that don't require GC interaction. Check out this talk from Unite Europe for much more detail about where we are going:


    I'm not sure about specific APIs, and we will still have some managed-to-native overhead, but C#7 will allow us to minimize that.

    I can't say yet. We're looking to get it out as soon as possible, so that we can start using ref returns in our API. So it is a high priority.

    We're not sure yet. The mcs compiler doesn't have C# 7 support now, but there is some being added. Roslyn is a good alternative, although in its normal batch compile mode it is significantly slower than mcs. However, Roslyn has a pretty awesome server mode where it keeps compiled versions of code that is unchanged in a cache. This makes it much faster than mcs in our tests.

    So I suspect we will use Roslyn, but C#7 support (however we can complete it) is the goal.
     
  17. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    Thanks for the really quick answer.
    That talk was super awsome btw, I didn't expect that job system stuff to be that cool (auto-rewriting code?, no vtables?, ... wow!)

    Sounds like Unity is on a great path when it comes to performance.

    I don't suppose you guys have using this for scene load integration on your road map yet?
    The integrate step of SceneManager.LoadSceneAsync still produces really bad (20ms+) hickups quite often even when you have no MonoBehaviours and only unity internal stuff (Terrain, SkinnedMeshRenderer).

    Any plans using that new system to improve that?
    Since you seem to be working on compiler stuff mostly, you might be the wrong guy to ask for that; In that case, would you happen to know who should I talk to in regards to that?
     
  18. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I'm unsure about scene load changes, sorry. I do know that we're working on jobifying a number of subsystems in Unity to improve performance, so I suspect that anything which is a bottle neck is on the table to be corrected.
     
    MechEthan and Alverik like this.
  19. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    That seems far more useful than the 'Assembly Definition' stuff put in 2017.2/3.. far more useful and easier than trying to manually tidy up a project filled with third party stuff. It's just a mess to trying to work with assembly definitions imo... and looks like it will be in the future completely useless?.. the first time I tried it, the biggest problem is zero automation/helper tools in the editor to assist users see where things could tidied up without breaking the project.

    So that looks far more useful and what is needed for an automatic boost to things like iteratative script changes with zero dev effort or thought to messing with doing assembly def's just to try improve recompile times.
     
    Qbit86 likes this.
  20. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    They said they'll cover doing the assembly definition stuff with an UI / Editor 100%. No manual fiddling around with json files. I think I even saw a screenshot somewhere already.

    Keeping a project clean is one thing. Sure it's important, but what's even more important is that you keep understanding your own project :p If your project organization is messed up, then sooner or later that'll bite you in the ass. And then faster compile times won't help you either.
    So the feature will not be useless in any case.

    However I agree, faster compile and reload times are really needed.
    I don't know how much faster the whole process will get though! Serialization and restarting (deserializing and instantiating the old stuff again) the CLR stuff take quite a bit of time as well I think, in addition to the raw compilation time.

    Anyone know what's the factor of that? Like how much % of the time is spent actually recompiling and how much is spent on serialization and instancing objects again?
     
  21. ArturSu1

    ArturSu1

    Joined:
    Oct 2, 2017
    Posts:
    10
    Are you going to support some Portable Class Library profiles alongside with .net Standard?
     
  22. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    No, we're not planning to support portable class library profiles. Our current plan is to support the full .NET 4.6 profile and the .NET Standard 2.0 profile.
     
    MechEthan, Overing, pateras and 4 others like this.
  23. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    .NET Standard is the replacement for PCL...
     
    MechEthan likes this.
  24. pateras

    pateras

    Joined:
    Jan 12, 2013
    Posts:
    50
    Why both? To ease an eventual transition away from 4.6?

    Also, supposedly .Net Core 2.0 has dramatically improved the performance of many APIs. I know Unity won't be built on Core, but given that Core is open source, is it being referenced to bring similar gains to Unity's .Net Standard 2.0 implementation?

    Thank you for the work that you're doing, and for maintaining good communication and transparency with the community!
     
  25. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    for the same reason that now we have full 2.0 and subset, except .net standard apis are not chosen arbitrarily by unity

    namely, subset/standard have less API but has a smaller build size and should be aot friendlier

    full profile is if you have something that don't support standard
     
  26. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    Technically the Standard profile is meant to separate .NET from Windows-specific features, whereas the full (Framework) profile retails all those dependencies (GDI, certain approaches to crypto, etc)
     
  27. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    As @M_R said, the .NET Standard 2.0 profile is nice for a smaller size, and it is easier to make the code work on AOT platforms. In general, we cannot support all of .NET 4.6 on all platforms. Much of that profile is just too Windows-centric or desktop-centric. That makes creating reusable code across all platforms Unity supports rather difficult.

    We can support the whole of .NET Standard across all of our platforms. So if you are writing platform-independent code for Unity, then .NET Standard will be the profile to target.

    We're planning to continue support for .NET 4.6 though for those users who need more than .NET Standard.

    Xamarin is pulling in much of the class library code open sourced by Microsoft to Mono. As Mono gets that code, Unity will also get it. I'm not familiar with specific performance gains, but in general, we like the idea of sharing more class library code so that we can get more consistent behavior.
     
    Thaina and pateras like this.
  28. Deleted User

    Deleted User

    Guest

    Wow nice to listen about news!

    How did you write embedded mono runtime into application. I already read history of mono website. They say team made unity3d with mono. Wow awesome idea. I am really sad because I already tried mkbundle with cygwin and Visual Studio 2017 Community because i want try application like Unity3D program or WaveEditor ( it is ready released but it is very unsafe because WaveEditor forgets protection with mkbundle. ) Why does after compiler for me with stupid openning console window. But i already check my application is target for winexe and after compiler via gcc from cygwin than result looks like crazy why does it need openning console window or did I create simple project c++/+ ( empty project or win32 project ) with embedded packed object ( mkbundle -oo embed.o but Visual Studio doesn't know gcc's embedded packed object.) Thanks i search google. But google doesn't help me.

    Sorry for my bad English!

    //Edit

    Why not use Gtk# 2.xx? Gtk# 2.xx is really stable because it works fine with opengl viewport like DirectWidget or ViewportWidget with libgtk-win32-2-0.dll ( it's like embedded opengl container ) and OpenTK 3.0 / 2.0.
    WaveEngine uses Gtk# 2.xx and OpenTK 2.0 and SharpDX ( for DirectX , Windows Users only )
     
    Last edited by a moderator: Oct 19, 2017
  29. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    The Mono project has some good documentation about how to embed the Mono runtime in a native application. You might want to check them out here: http://www.mono-project.com/docs/advanced/embedding/

    Regarding Gtk#, I'm not sure it supports enough platforms for Unity. We ship our code for all desktops, mobile, consoles, etc., so our GUI code needs to be very cross-platform.
     
  30. Alloc

    Alloc

    Joined:
    Jun 5, 2013
    Posts:
    241
    Hi Josh,

    was wondering if you could give any updates on the new GC integration progress, ideally something like a tentative release date / version?
    Think this has been talked about for something like two years now and it's still in the "In Development" category on the roadmap while IMHO a very important improvement to come.

    Thanks for all the updates on the runtime update progress :)

    Regards,
    Chris
     
    MV10, Alverik and Qbit86 like this.
  31. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    Will a new GC (if we even get one in the next 5-10 years) even bring that much improvement to the table?
    A thing that does a partial collection, so it can be split over multiple frames, would be a real improvement.
    But I don't know if that is even (easily) possible.
     
  32. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Unfortunately we don't have a tentative release date now. We're working on internal changes in Unity to allow it to use a moving, generational GC, and we have some prototypes with SGen, the GC from Mono. However, there is a good bit of work left to ensure that everything in Unity is working correctly.
     
    Alverik and dadude123 like this.
  33. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    The improvement really depends on the project. In many cases a generational, moving GC should be beneficial. A generation 0 collection should happen in less than 1 ms on most platforms. Generation 1 collections will probably take 1-2 ms and generation 2 collections can take up to 10 ms, which is about where we are now with a conservative GC. Of course these are all ball park numbers, so don't take them as guarantees! Generation 2 collections don't happen too often, but they do occur. But yes, we could split the equivalent of what is an entire collection now over multiple frames.

    So we're looking at a number of alternatives, including the exposure of GC control hooks on the Unity API. These might allow the GC to not collect for a certain time, then collect later when you know it is "safe". I'm unsure though about the shape of this API, as it is still early in development.

    In addition, we're moving more and more toward allocation-free APIs, and tighter control of memory layout in general. C#7 will bring byref return values, which will allow us to evolve much of the Unity API to be allocation-free.

    Finally, check out Joachim's talk from Unite Europe this year:
    . The C# job system entirely avoids the GC.
     
    Thaina, MechEthan, MV10 and 2 others like this.
  34. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    Could you perhaps make a concerted effort to specifically hunt for allocating APIs?

    Asking for a GC-free version of a single method is not near sexy enough to climb the suggestions rankings. At the same time, there's very many APIs that currently allocate and return arrays.

    It feels like allocating APIs are getting fixed in a very slow, ad hoc way; a while ago most of the GetComponent's got a nonalloc version, but a lot of similar methods (Like the FindObjectsOfType and such) didn't get the same love.

    My favourite is CalculateFrustumPlanes:

    Code (csharp):
    1. public static Plane[] CalculateFrustumPlanes(Matrix4x4 worldToProjectionMatrix) <= public API
    2. {
    3.   Plane[] planes = new Plane[6]; <= cry
    4.   GeometryUtility.Internal_ExtractPlanes(planes, worldToProjectionMatrix); <= private API
    5.   return planes; <= cry more
    6. }
    A large push to fix those things would be a large help in reducing allocations. Often these are also not APIs that will be helped by ref returns - you'd not return a reference to the result of FindObjectsOfType.
     
  35. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I believe that we have people working on this, although I'm not sure about the progress. I'll bring up CalculateFrustumPlanes specifically with our scripting team though, so make sure they are aware of it.
     
    AdmiralThrawn and dadude123 like this.
  36. Deleted User

    Deleted User

    Guest

    @josh thanks GTK# 2 is really stable because WaveEditor uses native with GTK# 2 with Gtk Runtime 2.x

    But I know that. Gtk Runtime 3 and Gtk# 3 are really unstable because they haven't any methods like onExposedHandler from OpenGL Viewport ( it is like magic of eventhandler ) or any features of Gtk#2 2 and Gtk Runtime 2. Of course support platforms like Windows, Mac, Linux and FreeBSD.

    FreeBSD has same Mono Runtime ( But somebody need compile and install )

    Wait I see "GC" Oh no you won't support and how does it happen with Mono Sgen 2.0 dll
     
  37. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    MechEthan and Baste like this.
  38. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    @Joachim_Ante Have you considered implementing Awaitable-Awaiter Pattern over job system? Async/await in C# does not rely on predefined `Task<T>` or `ValueTask<T>` types only.
     
    MV10 likes this.
  39. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    @JoshPeterson ...Or maybe I've mentioned wrong username @Joachim_Ante for the speaker from video above, so he didn't receive notification from this thread?
     
  40. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    You know Joachim Ante is one of Unity's co-founders and CTO right? (like executive level/boss/big tamale, you know?). Doubt he'll be replying very often in the forums. He's most likely very busy with other stuff...
     
    Last edited: Oct 25, 2017
  41. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Let me go a little bit off topic. This summer I visited CERN in Geneva, took a guided tour. And you know what is interesting: tours are free, and they don't have dedicated guides for tours. It's every professional physicist's responsibility to become a guide at some point, when it's his turn. It does not matter if he or she is PhD boss in some lab. It's big Nuclear Research Center, but they don't think that popularization, explaining, answering are below their level. They are not too busy for stuff like this.
     
    MechEthan and dadude123 like this.
  42. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
    Invalid conclusion. I ran a very successful business. Various government-mandated activities put demands on my time regardless of whether more important things needed my attention.
     
    Alverik likes this.
  43. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    I don't think you can compare that kind of externally funded research facility (paid by multiple groups and even countries) with a business (where the objective is keeping your company afloat and profitable). Plus, I doubt the director of the facility was the one giving you that tour... I humbly doubt a place like CERN, which mostly consumes resources, has the extra money to hire staff just for that (it already spends tons in equipment, maintenance, researcher's payrolls and what not).

    And, well, I also doubt having the "boss" from some lab busy somewhere else is going to affect the "company" in any way, since their aim is different...
     
    Last edited: Oct 25, 2017
  44. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    No I don't.

    I do not know him as CTO or co-founder of something. I only know him as “that guy from Unite Europe 2017 video, that Josh has referenced above”. That's all. In the end of that session he asked for questions, and people asked, and there was nothing like “I'm too busy being a Big Boss to answer your technical questions”.
     
  45. npatch

    npatch

    Joined:
    Jun 26, 2015
    Posts:
    247
    Settle down. Perhaps @JoshPeterson can mediate.
    On the other hand, @Qbit86 that session was part of a conference that most of the important people in the company attend since it promotes the engine. It's not the same. I doubt he's obligated to be in the forums nor does he have to answer questions in the forums. Perhaps he will though, perhaps he won't. At any rate, it's ok not to know what his capacity is so let's just end this here. No reason to further sidetrack this thread.
     
    Alverik and MV10 like this.
  46. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @Qbit86

    I'm not sure about this, but I'll pass the question along to the team working on this feature. Although Joachim was demoing this feature, and he is involved in its development, there is a team working on it with him. I'm sure that someone knows the answer - I'll try to track it down.

    As for Joachim's presence on the forums, I'm not sure.
     
    MechEthan, Thaina, npatch and 2 others like this.
  47. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    @Qbit86 A few months ago I talked about this option with @Joachim_Ante so it has been brought into the discussion, but we haven't made any formal study about this option yet, so can't tell for now if we will implement this or not...
     
    VOTRUBEC, MechEthan, Thaina and 3 others like this.
  48. npatch

    npatch

    Joined:
    Jun 26, 2015
    Posts:
    247
    I just watched this.
    Any plans in incorporating this as well? Or will you favor your own NativeArray over this due to it being compatible with the JobSystem?
     
    Qbit86 likes this.
  49. Alloc

    Alloc

    Joined:
    Jun 5, 2013
    Posts:
    241
    Any plans on supporting the ThreadStatic attribute?
     
    Qbit86 likes this.
  50. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Doesn't it just work?