5 ms·
All the points are valid but they are peculiar to Java, not to all managed high-level languages. C#/.NET, for example, have unsigned types, value-type arrays an
by ot 15y ago
All the points are valid but they are peculiar to Java, not to all managed high-level languages. C#/.NET, for example, have unsigned types, value-type arrays and structs, memory mapped files and specialized collections.
As an example, the C# port of Sqlite is sometimes faster than the C version on queries, although updates are slower, despite Sqlite is a highly optimized C library.
EDIT: link http://code.google.com/p/csharp-sqlite/wiki/Benchmarks http://code.google.com/p/csharp-sqlite/wiki/Benchmarks
- kevingadd 15y agoIt's also worth pointing out that the C# port of SQlite omits using certain C mechanisms (like pointers) in favor of passing copies of byte arrays around. You'd expect this to make it slower, but in many cases, it doesn't! (C# supports pointers, but the port doesn't use them so that it'll work in limited environments like Silverlight)
- gaius 15y agoThe .NET runtime is well optimized for that sort of thing, as it needed to be for F#.
- alexchamberlain 15y agoThis is slightly off topic, but a good read... http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/ http://cpp-next.com/archive/2009/08/want-speed-pass-by-value...
- zokier 15y agoSlightly offtopic, but I wonder how much overhead in those benchmarks comes from calling native code from .NET runtime? An interesting data point could be benchmarking equivalent implementation in C or C++, avoiding the overhead of native-managed transition.
- ot 15y agoIn my experience, interfacing native code via C++/CLI has negligible overhead, unless arguments are big and complex data types, which have to be converted to .NET types. Otherwise, unsafe regions have practically zero overhead, and they are close enough to the metal.
- mdeicaza 15y agoAdditionally, C# collections do not need to box. List<int> uses an actual array of integers as its backing store instead of an array of objects that contain boxed copies of the integers. There is a port of JGit to .NET called NGit, which is what we use for MonoDevelop. The port is maintained with an automatic tool that converts Java code to C# code, you can find it here: https://github.com/slluis/ngit https://github.com/slluis/ngit
- ot 15y ago> List<int> uses an actual array of integers as its backing store instead of an array of objects that contain boxed copies of the integers. Yes, that's what I meant with specialized collections :) BTW, I didn't know about the awesome NGit, automatic conversion from Java is really impressive!
- stcredzero 15y agoAll the points are valid but they are peculiar to Java, not to all managed high-level languages. C#/.NET, for example, have unsigned types, value-type arrays and structs, memory mapped files and specialized collections. I heard about related stuff happening while I was working at a Smalltalk vendor. The programmer who was implementing the network cryptography library would just call up the VM engineer and ask for goodies like support for large bit arrays, and he'd get them in for the next VM release. The programmer was able to beat some of RSA data security's (poorly implemented) reference DLL's written in C by 3% with a Smalltalk program. In the Smalltalk environments, it's easy to implement "primitives" coded in C, just in case you weren't internal to the vendor. With open VMs like Squeak, you can add your own bytecode to support optimizations if you want to.
- erichocean 15y agoAlthough Sqlite is highly optimized, it's got what amounts to its own VM internally, and doesn't really use C to the fullest. It's not surprising to me that the C# version of that VM does as well (or better) for this particular codebase.
- oconnor0 15y agoCan you explain more what you mean about SQLite having roughly its own VM?
- erichocean 15y agoSee: http://www.sqlite.org/different.html http://www.sqlite.org/different.html Money quote about half-way down the page: "SQL statements compile into virtual machine code" Every SQL database engine compiles each SQL statement into some kind of internal data structure which is then used to carry out the work of the statement. But in most SQL engines that internal data structure is a complex web of interlinked structures and objects. In SQLite, the compiled form of statements is a short program in a machine-language like representation. Users of the database can view this virtual machine language by prepending the EXPLAIN keyword to a query. The use of a virtual machine in SQLite has been a great benefit to the library's development. The virtual machine provides a crisp, well-defined junction between the front-end of SQLite (the part that parses SQL statements and generates virtual machine code) and the back-end (the part that executes the virtual machine code and computes a result.) The virtual machine allows the developers to see clearly and in an easily readable form what SQLite is trying to do with each statement it compiles, which is a tremendous help in debugging. Depending on how it is compiled, SQLite also has the capability of tracing the execution of the virtual machine - printing each virtual machine instruction and its result as it executes.
- itmag 15y agoOff-topic but relevant: I've been looking for info on just how database software does what it does. Ie from parsing the SQL query to hitting the disk, and everything in between. Anyone got any links or books?