Mono's New .NET Interpreter
mono-project.com
mono-project.com
It's also quite interesting that the interpreter was dropped due to the complexity introduced by having generics in the runtime. A long time ago I thought it was self evident that type erasure was a poor way to do generics, but Brian Goetz has been arguing persistently for years now that type erasure isn't necessarily a bug, just a different tradeoff. With runtime complexity being one of the factors that weighed into the decision ... something that's easier to understand now I read this blog post.
There are some things I like about .NET though it was a long time since I did any, but HotSpot seems so dramatically far ahead and the distance is increasing. The major selling point of .NET over Java originally was supposed to be great multi-language support (well, and better Windows support), but there are way more languages targeting the JVM than the CLR these days. HotSpot does tiered compilation, it now does AOT compilation too, it has a new JIT called Graal that either matches or completely smokes the best available runtimes for almost every language, and IntelliJ is every bit the match for Visual Studio. And it's all cross platform.
So what's .NET's major selling point these days?
Benchmarkgame scores reached basically parity between java and C# once .net core 2.0 dropped
.NET selling points:
* you can do some SIMD explicitly, more is coming
* you have control over when things are stack allocated or not. structs, stackalloc, slices
* you have unsigned ints
http://anthonylloyd.github.io/blog/2017/08/15/dotnetcore-per...
The point of explicit control is usually performance though. So if Java can give you near equal or better performance but without the developer having to explicitly specify as much, isn't that a win?
Benchmark game also lacks the benchmark the Mono blog post is all about - developer iteration time.
It would be, but often times the lack of explicit control causes you to need more verbosity in Java to get around it, because the JIT isn't all knowing. For instance say you want an array of 2D vectors (x,y) and you want them in line in the array for data locality. In C# you just make Vector a struct, and put the structs in the array. In Java you would have to just put float primitives in the array and alternate the x and y and keep track of it by hand. Minecraft suffers greatly from this.
As well, Java won't do anything but the most trivial automatic vectorization, and only on integers, and SIMD can be a huge win at times. I'm looking forward to more complete support droping for .net
>Benchmark game also lacks the benchmark the Mono blog post is all about - developer iteration time.
Single file static AoT compilation. Does the JDK support this yet?
For those that rather use only OpenJDK, there is Linux x64 AOT support on Java 9, with improved support for other platforms in Java 10 roadmap, some of it already in master.
As for F#, currently it is lacking some love from.NET Framework, UWP and Visual Studio teams, which always think about C# and VB.NET terms. Even C++ seems to be better supported.
Without a reason to keep the interpreter (the world was a JIT-friendly place back then), it made no sense to maintain it.
But times change, statically compiled environments are more common nowadays (iOS, PlayStation, Xbox, tvOS, watchOS) and with it the need to have dynamic capabilities.
To put things in perspective, adding generics to the revived interpreter probably took an engineer that was not familiar with .NET about 4-6 weeks of work.
Much better unmanaged interop story: [DllImport] (btw it works on all platforms, e.g. on Linux it imports from .so libraries), structures, unsigned integers.
Better multithreading: thread pool, synchronization contexts, async-await.
Unsafe code, pointer arithmetic.
LINQ
https://msdn.microsoft.com/en-us/library/windows/desktop/aa3...
But they’re rarely found in APIs, and there’s Marshal class in the framework to implement manual marshaling by reading/writing stuff at unmanaged memory addresses, even without /unsafe compiler switch.
struct VariableLength {
public int fixedSize;
public fixed int varSize[1];
}
Of course, this also means that you have to use stackalloc or other manual allocation to actually get a properly sized block of memory, computing said size yourself; but you also have to do it in C with malloc: byte* p = stackalloc byte[sizeof(VariableLength) + 10 * sizeof(int)];
var vl = (VariableLength*) p;
Once you have a pointer, though, you can do vl->varSize[i] etc - this works because the type of vl->varSize when you access it is int*.Thanks to JRuby guys and Project Panama, Java will eventually get a .NET like interop story, but it is still in the future. :(
https://blogs.oracle.com/java/the-javaone-2013-technical-key...
<quote> He mentioned JNI 2.0 and said, “It just shouldn’t be so hard to integrate Java with native code after all these years.” </quote>
For the full context, you need to watch the keynote.
@Header(path="unistd.h")
While indeed very easy to use, that API is extremely hard to implement in the runtime to make it work not just for toy examples. Authors of real world libraries do all kinds of weird stuff in their C headers: they abuse C preprocessor, implement compiler-specific hacks, and even include pieces generated by external tools.Is platform_s_ here, Windows 10, Windows 8 and other ms platforms Last time I looked GUI on Mac and Linux was far from excellent something on par with python binding to QT/gtk works but not enjoyable
- As a consultant if I am handed a .NET project, even if it's a ios, android, web app, or a wpf application, then I'm usually familiar with 100% of the ORMs/PDF libraries/GUIs/build systems/source controls/IDEs/web frameworks they use(excluding client side web). I can come up to speed and get running quickly whether it was built last year or 10 years ago. It's the exact opposite of the javascript environment where two different javascript apps have less in common than a ruby and python app. It also allows me to meet all my clients need well enough on one platform.
- Because of the previous item, it's perfect for enterprise which needs to be able to scale up and down teams internally.
- Tooling is built for ease of use and is amazing. A lot of tooling from my experience in the java world is more powerful but with much much steeper learning curves. Leading to far more specialization.
- Visual studio is a best in class IDE.
- It's not java. From a language perspective java is still playing catch-up.
Java is great, there are a lot of amazing open source projects on it, the big data story on java is far more compelling, you can write much better Android apps, and and large multi-department transactions financial/enterprise software. But it is in no way shape or form superior to .Net in all ways.
That and the alarming amount of mixed information you get on whether or not using X is a better idea than Y, for ill-defined (from all angles, including MS), deprecation-related reasons. At least that was my experience a couple weeks ago when I got placed on a one-off .NET project.
I'll admit that I'm not terribly experienced with .NET's standard library. But I am very familiar with C# as a language and I'm comfortable using it. It was rather frustrating for the stumbling block to be what it was.
What debugging features does IntelliJ have that are of equal or superior utility compared to IntelliTrace?
https://blogs.msdn.microsoft.com/zainnab/2013/02/12/understa...
This is often repeated, but it turns out that the JVM and CLR have roughly the same number of high profile languages:
Specifically, the CLR enjoys the following mature languages:
C#
F#
VB (which has some distinct advantages over C#)
C++/CLI
PowerShell
IronPython
Nemerle
It's also worth noting that Clojure absolutely works on the CLR, and F* (F# with a more powerful type system) just hit version 0.9.C# (and VB), get a bit of love of HN, but they're even more powerful than they get credit for. C# has monad comprehensions, a metaobject protocol[1], and can straight-forwardly simulate type classes (in the form of implicit conversions to constructed classes). So, as a language, C# can get close to both Scala and Clojure even without having higher-kinded types, multimethods, or macros.
[1] https://books.google.com/books?id=QGciuyBRyU0C&pg=PA119&lpg=...
The consequences of having multiple competing cross-platform options are already evident when using tools like intellisense in VS Code where you can (or used to be able to) switch between Mono and .NET Core runtimes and certain libraries were only compatible with one. And then there are build tools like Paket which currently only support Mono even though Paket itself can provision .NET Core runtimes.
With .NET core being open source they should find a way to work with the mono team.
Of course you can't import .NET Core libraries into .NET Standard so in the end we actually made projects for each of them with links back to the .NET Standard libraries' files.
Miguel posted the article and he's a Microsoft Employee for sure.
I think the runtimes are slowly converging. The main issue at the moment is that Core is more focused on Web and back-end targets. To replace Mono, it needs to support UI targets such as desktop Windows, Mac and Linux, as well as mobile targets such as Android and iOS. It'll happen. Most of the .Net platforms seem to use the Roslyn compilers these days. Next step is to converge at a library level, then at a VM level I think.
It is, at least, good to see Microsoft attempting to prevent the opposite problem (fragmentation) by keeping the .NET Standard up-to-date.
https://docs.microsoft.com/en-us/dotnet/standard/net-standar...
https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcin...
They are very different things and due to the universal misunderstanding and terminology misuse easy to mix up.
I believe you do not have a choice. iOS, Android, macOS, Linux Desktop goes to Mono. No choice there. Application Servers go to .NET Core. No choice there considering performance and Cloud deployability. Windows Legacy goes to the .NET Framework. No choice there. Modern Windows App goes to UWP (another .NET Core).
I do not see a choice except when you want to run a service on Mono. Which everyone will tell you not to do.
Why?
And this: https://stackoverflow.com/questions/27266907/no-appdomains-i...
And did I mention this? https://github.com/dotnet/coreclr/pull/8677
As long as we have things like that, and as long as .NET Core continues to pander only to the lowest common denominator of developers, then the Mono project is still providing value. It is not a matter of "competing".
These problems are eclipsed by the the marginal success of the 95-99% of use cases that are covered by .NET Core.
One of the lesser-known areas that C# and .NET has shined, involves plugin and modular development. AppDomains and secure code regions are a feature of the runtime. For more esoteric use cases, the classic .NET runtime itself is customizable, with replaceable COM interfaces using the C++ hosting API. This is how SQL Server implemented stored procedures that could be written with C#.
The way .NET Core has treated the issue is tantamount to a betrayal of trust. I understand that they are trying to take things in a different direction, but doing so undermines the other features that .NET provides, and does so well with. Not to mention they did promise to work on, and merge the feature, before leaving people hanging with no further updates in communication. A cross-platform .NET Core that doesn't have this kind of feature is not going to do much that Python or Java cannot do. We should be far more worried about .NET Core competing with .NET Framework, than .NET Core competing with Mono.
Is Microsoft trying to provide a good tool, to empower developers to build things that could not be easily built before? Or is the primary goal to be seen as friendly to the Open Source Community, by providing yet another dumbed down, cookie cutter cross-platform SDK that deserves no relevance? Are they intentionally omitting or delaying features that one would use in more advanced scenarios, forcing developers to make a choice to use classic .NET Framework (Windows/Mono)?
It is starting to seem like the same old tricks by Microsoft, just more cleverly hidden.
For us to consider to use .NET Core instead of Java or C++ for UNIX-like OSes, it still needs to catch up a bit with its bigger brother.
.NET Core has been a huge rewrite of the old framework, focusing on common scenarios which are easily cross-platform first, then the harder ones later. E.g. System.Drawing, which they eventually included (in 2.0 in believe) via incorporating several implementations for each target architecture, including one from Mono.
They'll probably get to AppDomains eventually, assuming it isnt outright impossible on linux/osx or introduces a massive security hole.
But not doing it right now cause you want it isnt evil: which is more important? Full support for System.Crytography, or say Oracle Ado.NET, or runtime loading/unloading of dlls? Hint, the answer isnt dll unloading.
While Silverlight did produce the first portable version of .NET and produces a lot of the code that allowed .NET to be portable, this code has been now retrofitted into the main CoreCLR and the VM source code has been upgraded.
What you see in the public CoreCLR is now the state of the art and while I do not know how the exact mechanics work, my understanding is that the CoreCLR and the .NET Desktop VM that ships source codes are very close to each other - modulo branches, deliverables, freeze dates and other loose ends.
On the library front, there has been a lot of rewriting for the sake of portability, cleaning up the code, and making the code more maintainable, and bringing it to the 2017 standards of coding.
And it's not a matter of priority or security, it's a matter of transparency. The community was promised a review, and stress test, and that someone from MS would be working on it full time. They followed up with more promises multiple times. And then silence. You're completely missing the point.
I don't understand why they need so many different "cross-platform" standards. Why is the platform so fragmented when MS controls the whole thing?
The standard is either CLR (Common Language Runtime) or CLI (Common Language Infrastructure), I'm not entirely sure.
Edit As far as I can tell, yes, even Miguel de Icaza is consistently misusing these terms.
Edit 2 - Nope, I'm wrong!
(Yes, there are also ECMA standards for the CLR/CLI, C# language, and a somewhat small subset of the BCL [Base Class Library]. .NET Standard subsumes those underlying standards and then specs out a much larger set of the BCL and even some libraries that aren't strictly BCL but may as well have been in the way they've become standards such as ADO.NET.)
https://docs.microsoft.com/en-us/dotnet/standard/net-standar...
There is a nice talk about it, somewhere on YouTube.
Then there was the whole 8.0, 8.1 with UAP, and finally UWP transitions.
The two only good things from UWP for .NET devs were finally getting .NET Native, which should be there since 1.0 given the Delphi roots of Anders, and the COM Runtime model that was in the genesis of .NET (formerly known as Ext-VOS).
I think the talk you refer to, is one from OS research group at MSR.
UWP/UAP is a new UI stack from the Windows team BOUND to a CoreCLR. That is different with the existing .NET UI technology stacks.
Additional, the CoreCLR and its more modern Assembly packaging (System.Runtime vs mscorlib) made the code difficult to share (recompile or PCL). This is solved now by the .NET Standard.
Which is what I meant with "mess created by Sinofsky regarding .NET, UWP and C++/CX.". I do have UWP experience since WP 8.
Thanks for the link about the talk.
.Net Core is one implementation of the standard. .Net 4.6 is another implementation of the standard. Mono, Xamarin, Universal Windows Platforms are other implementations.
The idea is that any code written for .Net standard, will work across the different implementations.
It's true that .NET Standard 1.0-1.6 had a lot of gaps but these should be rectified with 2.0 now so you shouldn't run into these problems anymore (otherwise there's usually a good reason why a method/API is missing from the standard).
Disclaimer: I'm working on Mono for Microsoft/Xamarin, primarily class libraries and tools.
Contrast to languages where there isn't a spec, or the spec is the interpreter, such as Perl 5 (Perl 6 actually has a specification and multiple implementations or various levels of conformance), or things in between, such as Python with the Python Language Reference. There are benefits and drawbacks to a standard/specification. One benefit is that it's easy for someone to start their own implementation and test for conformance and have a high degree of surety whether it will work with existing programs. One downside is that when there's a problem found in the spec, it often requires more work to fix, as the changes need to propagate out to the implementations, which will have their own timelines as to when they can implement it.
I thought the "dedicated use case" of .NET Core was to be THE cross-platform .NET implementation.
With factored I meant more: native compiled, three shaked, WebAssembly compiled, iOS allowed, Arm, PowerPC, ....
Samsung already rebooted the SDK so many times, and the platform lack of security is well known, I doubt it will ever get serious beyond a few watches and TV sets from Samsung.
Today, when you checkout the Mono source code, it brings CoreRT and CoreFX.
From a user perpective, we have worked to make a universal API surface that goes everywhere Mono, .NET or Xamarin go, it is called the .NET Standard, and last month we released a major upgrade to .NET standard that grew the API surface across the board.
As for the runtimes, they have different pros/cons so they currently can not be unified into a single one, so we need to maintain different ones, but we are working to make the tooling work better across the board.
This blog post has a few more details and examples of the WebAssembly work: http://www.mono-project.com/news/2017/08/09/hello-webassembl...
Disclaimer: I'm working on Mono for Microsoft/Xamarin (primarily class libraries and tools).
There is a programming language where every new expression causes incremental compilation and linking inherently, natively: it’s called Lisp.
When you use Roslyn you still need either a JIT or an interpreter to execute the output of Roslyn. You can't ask what is the benefit of using the interpreter over using Roslyn as you cannot do that. They don't fit into the same place in the system. They don't do the same job. They aren't alternatives.
It's a nonsense question.
> When you use Roslyn you still need either a JIT or an interpreter
Yes: Assume I'm already in a .NET appxontext so yes I have the JIT available. Does that make the interpreter less attractive as I can just load compiled code there?
I'm guessing then the benefit might be less initial overhead, but at the expense of slower execution?
> but this type of scripting is exactly what I use Roslyn for
Because you aren't using Roslyn to execute anything. You're using it to compile C# to CIL. That CIL is then executed by a different part of the system - the JIT. It's that entirely unrelated part of the system that is being talked about being replaced with an optional interpreter instead.
Roslyn goes from C# to CIL.
The JIT and interpreter execute CIL. They don't know or care that it comes from Roslyn and the fact that you use Roslyn or the command line C# compiler to generate the CIL is irrelevant.
You're being tripped up by the fact that the system has multiple levels of compilers. You're thinking about one level but this discussion is about another level.
But anyway there is actually a helpful answer to this question:
> what is the benefit of interpreted scripts vs dynamic compilation of scripts in the context of , for example, app scripting?
The interpreter will probably use less memory and run your code faster first time. You probably don't care about less memory in a game unless you are running in a very constrained system, and you probably don't care about first-time execution as either these scripts run every frame and so it's critical they're very fast, or they run once a few seconds or so in which case who cares how fast they run.
Right - with Roslyn Run("somecode") means creating an assembly from the code, then loading it into the current AppContext and executing it there. If I were to run an interpreter then Run ("someCode") is interpreted. I get that.
My question was still only: would an application chose one or the other, when given both options. I get that they are completely separate ideas and Roslyn doesn't do anything an interpreter does (Roslyn and jit does) - but "compile+load" and "interpret" both offer a way to solve the Run("somecode") problem, which is why they are still somewhat related in the specific context of a .NET app with scripting
Do you need to care as an application? Ideally no :-) It should be transparent to the user and it's the runtime's job to do the best available thing for you. (Sure, the runtime can be tweaked for specific workloads etc.)
In Mono we aren't there yet: the interpreter is currently useful for restricted targets like iOS, where a JIT can't be used due to security concerns and AOT comes with certain limitations (that is, loading assemblies at runtime and execute them). If you want to use Mono's Interpreter to run roslyn, you can explicitly tell the runtime to do so, but it doesn't make much sense today, because it will give you less performance than the available JIT; we don't support switching the execution engine on the fly for single methods yet (it's also called tiered compilation).