Lock-free collection in libgee: hazard pointer

From version 0.8 libgee have support for lock-free collections. While they can be used as a drop-in replacement for any other there are a few ‘gotchas’ that user needs to be aware of if (s)he wants to use them efficiently, of if (s)he wants to implement collection themselves.

Continue reading

Posted in Libgee | Tagged , , , | Leave a comment

Libraries in Vala – ABI compatibility – part II

In previous post I’ve described what ABI is. Now the time for potential problems which you can run into with Vala – unfortunately the list might not complete so please threat it as a guideline rather than definite description.

For the purpose of this post I’ll assume that breaking API is necessarily breaking the ABI. There are exceptions I’ll describe in part III.

Continue reading

Posted in Vala | Tagged , | Leave a comment

Hello Planet Gnome

The blog have been added today to GNOME Planet. My name is Maciej Piechotka and I’m a libgee maintainer, but currently I’m shifting my focus a bit towards core Vala, especially with regard to performance optimization. In addition I intend to write a guideline how to maintain an ABI stability in Vala libraries, first part of which was published (eventually it will be migrated to wiki). Despite the claims it is quite possible.

Other than strictly GNOME-related topics I write also about other technical topics, for example typing(content might not be suitable for people averse to static typing) or build systems. Sometimes other posts might appear as well.

PS. Sorry for the earlier post – I misunderstood the bug comment. The blog was added as of today, not yesterday.

Posted in Blog, GNOME | Tagged , , | 1 Comment

Pre-announcing VaLLVM

Curently Vala simply generates C code and let the C compiler do its job. While in many cases it produces good code there are some cases which where compiler stack could use more domain-specific knowledge. The problem is that C was constructed as human-readable language and it’s optimization keywords are directed for writing in it directly, while Vala have more highier level knowledge and it needs to make the compiler deduce properties, which might be trivial for the code reader/writer.

For example consider the code below. This is very simple code, but the Vala compiler will treat the lambda as a full scale event. As the result instead of allocating the data on stack it will be allocated from heap. All the accesses will be done by pointer indirection after the lambda as data have escaped and evil stdout.printf might access it (for all compiler knows – it does). Furthermore the widget and this will be referenced during the cast and unreferenced afterwards – unnecessary as both values should be live the whole time.

class Test {
    void foo(Gee.List<Gtk.Widget> list) {
        double powersum = 0;
        int no = 0;
        int x = 0;
        list.foreach ((widget) => {
            Gtk.SpinButton? spin = widget as Gtk.SpinButton;
            if (spin != null) {
                double val = spin.get_value ();
                powersum += val * val;
                stdout.print("%d: %d, %d\n", no, powersum, x);
        for (int i = 0; i < 1000; i++) {
            if (x != 0) {
                stdout.printf("An error\n");
            } else {
    private int i = 0;

Continue reading

Posted in Programming, Vala | Tagged , | 11 Comments

Libraries in Vala – ABI compatibility – part I

As described before Vala have quite interesting mix of high and low-level features. One of elements one need to be aware in Vala is that there is an ABI, when the “ABI compatibility” is needed and how to keep it.

What’s an ABI and why should I care

Most programmers know about API, which is a contract about how the components should interact. ABI is also a contract however while API is on the source code level, ABI is on binary level.

The problem is that there is no automated check if library is ABI compatible. While there are some automated tools, they are only useful when one knows how to read the output.

Further problem is that the tools are not aware about Vala or GObject specific issues and can report a false positive or false negative if one’s not careful.

Continue reading

Posted in GNOME, GNU/Linux, Vala | Tagged , | 1 Comment

Futures and promises in libgee

In recent unstable releases of libgee contains Futures and Promises (please note that API is still not frozen so the exact details may change).

Future in a simples case is a value which might not be currently available. From the interface point of view it does not matter how exactly the value is received (it can be computed in another thread, got through the RPC, lazily computed etc.). Setting aside that a value it is functional, and functional programming is cool, it have concrete benefits over the callback such as composability.

While Vala have syntax support for asynchronious programming and it was tuned to I/O operations there are still a bit of missing pieces to fully use it in that way (including but not limited to synchronisation).

Continue reading

Posted in Libgee, Programming | Tagged , , , | Leave a comment

Vala ABI and branch prediction

Maintaining Libgee for some time I run into interesting phenomena – performance did not behave in a way most people would expect. When the highier-order functions were planned it was pointed out that Vala doesn’t have complex inlining required for fast usage of higher-order functions.

As shown by previous link the reverse is true. In hindsight it seems to be clear that source of discrepancy is due to shorthands we employed while analyzing the performance.

Continue reading

Posted in GNOME, GNU/Linux, Vala | Tagged , , , | 1 Comment

Don’t write your own build system

The title might be a bit controversial but at least it is catchy one. Recently I’ve seen a few posts about Shake, a make replacement with several improvements (such as more flexible dependency specification). There are also examples how to use it with say Vala.

The problem is that the Make and Shake are both rather quite low-level tools and while improvement in them is beneficial shake, at least currently, is not a replacement for autotools or CMake.

Continue reading

Posted in Programming | Tagged , , , , | Leave a comment

Statically typed red-black trees

I have met with claims that the static typing is useless as it is not mathematical proof (OK – for those knowing the discussion – I exaggerated a lot). However to large extend the static typing is prove of some sort and depending on the code it might be a prove of even quite strong properties.

As chosen field I tried to use LLRB trees – I have implemented them quite long time ago and I’ve run into problems that violated the pre and post conditions. Even when problem was discovered it took some time to find out the underlaying problems (my inexperience didn’t helped probably either)

I’ve tried to reimplement the code in GHC Haskell with following rules:

  • Using only ‘safe’ extensions
  • Making all functions total and without use of undefined or error
  • Ensuring that all properties of tree are preserved

Unfortunately this was my first time I used some of the concepts (like Zipper) so the implementation and description might be not the best (comments and corrections welcome).

Continue reading

Posted in Programming | Tagged , , | Leave a comment

(Rant) Difference between good and useful slides

Fortunately or unfortunately the presentations tend to be more and more popular sources of information. Be it a new library, language or future direction of a project the only possible way is either attend some presentation or watch it later.

Continue reading

Posted in Uncategorized | Tagged , , | Leave a comment