How optimized is Vala's generated C code on top of C code?

Is the code generated by Vala generated like normal manual C code? Is there any performance overhead when using a GObject system that does not use it?

NOTE. In my next C project, I study using Vala or not. A project is not a graphical application; it is an interpreter application that must be platform independent. I use gcc as a compiler.

+6
source share
4 answers

As a Vala developer, I would not suggest Val for a translator. In the interpreter, you will create many objects for the aster, data types, possible intermediate objects, codogen objects, etc. In Val I personally appreciated that the main overhead is the creation of objects (simple GTypeInstance, even GObject). Vala is designed to work with gobjects, but gobjects are not designed for quick placement.

So, for your project, I will still use glib / gio for cross-platform things like network, string utils, unicode, data structures, etc., because they have a clean, consistent and convenient API, but I don’t would create ast objects like gobjects / gtypeinstance. In the interpreter you need a quick selection, which is the whole point.

My personal advice: use vala if you want to create desktop applications, dbus services, gstreamer stuff or anything that affects the g * world, nothing more.

+10
source

It depends on what you would write C. In particular:

  • Since I can write code based on GObject code manually, what is your threshold? Handwritten based on GObject C versus Vala-written GObject-based C? Probably comparable, since Vala is going to generate more or less the same library calls as people.
  • GObject classes are technically optional. You can mark the class as [Compact] to skip all GLib code generation for the class, which will be much faster, although you will lose many functions, such as virtual methods, if you do. This will still have a bit more overhead than an object written in C, but it comes with a stream count of links and a few other things that a regular C programmer would not do.
  • Vala generates many temporary variables. If your C compiler has optimizations at all, most of these time series will be eliminated. The bulk of Vala's control structures correspond to their C counts, so Vala if will not be tremendously more expensive than C if .
  • Vala tracks memory management links at compile time. This is usually cheap, but it can cause additional duplication of arrays and strings. In particular, if you copy an unchanged string into a variable belonging to it, strdup will be automatically called. This means that the generated Vala will create more of these small temporary objects, but if this is really a problem, you can intelligently use unowned to limit their creation.
+5
source

The generated code is never optimized, like well-written manual code, because the optimizer cannot know the purpose of the design. However, the optimizer creates optimized code more consistently than the human programmer does. You should also define your goals, and then check to see if the performance requirements match the selected tools, and not vice versa. Optimization is not a design goal, it is a task that may need to be addressed, so first determine your requirements, and then think about how to achieve it.

Premature optimization is the root of all evil. :)

+2
source

The generated vala compiler code uses the GObject library. If you need to avoid GObject, I suggest using the aroop compiler, which uses a vase parser to analyze the wallcode, but does not use GObject in the generated code.

The Aroop compiler generates code that uses an object pool that is optimized for creating and manipulating objects. The collection of objects has data-oriented functions. For example, objects can be flagged and a flag can be selected when traversing objects in a very efficient way, and objects are at close range in terms of memory location.

The aroop compiler is used to record a shotodol project that does not have its own graphical interface. It has a module and a plug-in system. It has a command line interface that allows people to write a server application. An example server application using shotodol exists here as shotodol_web . I wish that people who like this project share their problems on the project page.

+2
source

Source: https://habr.com/ru/post/947077/


All Articles