Luca's meaningless thoughts  

Delegates and inlining

by Leandro Lucarella on 2010- 06- 28 15:30 (updated on 2010- 06- 28 15:30)
tagged d, delegate, dgc, en, gc, inline, inlining, optimization, performance - with 3 comment(s)

Sometimes performance issues matter more than you might think for a language. In this case I'm talking about the D programming language.

I'm trying to improve the GC, and I want to improve it not only in terms of performance, but in terms of code quality too. But I'm hitting some performance issues that prevent me to make the code better.

D support high level constructs, like delegates (aka closures). For example, to do a simple linear search I wanted to use this code:

T* find_if(bool delegate(ref T) predicate)
{
   for (size_t i = 0; i < this._size; i++)
      if (predicate(this._data[i]))
         return this._data + i;
   return null;
}
...
auto p = find_if((ref T t) { return t > 5; });

But in DMD, you don't get that predicate inlined (neither the find_if() call, for that matter), so you're basically screwed, suddenly you code is ~4x slower. Seriously, I'm not joking, using callgrind to profile the program (DMD's profiler doesn't work for me, I get a stack overflow for a recursive call when I try to use it), doing the call takes 4x more instructions, and in a real life example, using Dil to generate the Tango documentation, I get a 3.3x performance penalty for using this high-level construct.

I guess this is why D2's sort uses string mixins instead of delegates for this kind of things. The only lectures that I can find from this is delegates are failing in D, either because they have a bad syntax (compare sort(x, (ref X a, ref X b) { return a > b; }) with sort!"a < b"(x)) or because their performance sucks (mixins are inlined by definition, think of C macros). The language designer is telling you "don't use that feature".

Fortunately the later is only a DMD issue, LDC is able to inline those predicates (they have to inhibit the DMD front-end inlining to let LLVM do the dirty work, and it definitely does it better).

The problem is I can't use LDC because for some unknown reason it produces a non-working Dil executable, and Dil is the only real-life program I have to test and benchmark the GC.

I think this issue really hurts D, because if you can't write performance critical code using higher-level D constructs, you can't showcase your own language in the important parts.

The IT Crowd S04

by Leandro Lucarella on 2010- 06- 26 23:38 (updated on 2010- 06- 26 23:38)
tagged en, serie, series, the it crowd, tv - with 0 comment(s)

The IT Crowd is back, a new season (4) has started yesterday.

Hurray!

Youtube, corneta, botón

by Leandro Lucarella on 2010- 06- 26 21:52 (updated on 2010- 06- 26 21:52)
tagged 2010, corneta, es, mundial, sudáfrica, vuvuzela, youtube - with 0 comment(s)

Youtube agregó un botón a los videos que es una pelotita de fútbol que todo lo que hace es agregarle ruido de cornetas (¿¡ma qué vuvuzela ni vuvuzela!?) de fondo al video.

Genial! Para cagarlos a trompadas...

Página de la FIFA

by Leandro Lucarella on 2010- 06- 24 13:25 (updated on 2010- 06- 24 13:25)
tagged 2010, es, fifa, mundial, rant, sudáfrica, web - with 4 comment(s)

¡Qué verga que es la página de la FIFA!

Solo quería compartir ese pensamiento con ustedes...

DMD 64 bits

by Leandro Lucarella on 2010- 06- 21 14:37 (updated on 2010- 07- 17 15:37)
tagged 64 bits, amd64, backend, compiler, d, dmd, en, x86-64 - with 1 comment(s)

Big news: DMD 64 bits support has just been started! It almost shadows the born of the new public DMD test suite (but I think the latter if far more important in the long term).

Mr. Orkester

by Leandro Lucarella on 2010- 06- 16 01:43 (updated on 2010- 06- 16 01:43)
tagged es, indiefolks, live, mr. orkester, music, sebastian uul, video, vimeo - with 0 comment(s)

Me gusta Indiefolks (si bien no puedo dejar de pensar en los precursores, como The Black Cab Sessions o La Blogotheque's Concerts à Emporter cuando lo veo).

Hoy descubrí a Mr. Orkester gracias a ellos:

Directo desde Noruega nos llega Sebastian Uul, más conocido como MR. ORKESTER y que se gana la vida viajando por todo el mundo tocando en la calle, en este caso hace parada en Buenos Aires.

Con formato multi-instrumentista cuenta con una batería casera colgada en la espalda, guitarra acústica, armónica, pandereta en pie derecho. Posee una energía y una personalidad que lo convierten en uno de los exponentes más originales de la música urbana moderna.

En este caso y a pedido de él, nos fuimos hasta el puente de la facultad de derecho donde Mr Orkester siempre quiso tocar pero que debido a la falta de gente no le convenía.

Sebastian provoca una curiosidad pocas veces vista en artistas callejeros; algo me dice que dentro de poco tiempo esos cables que cuelgan de su guitarra y la armónica oxidada se van a cambiar por escenarios más acordes a la calidad musical que representa.

Es un artista, siempre dispuesto a trasmitir alegría y energía positiva en cada tema que toca. Con una voz desgarradora, nos recuerda al gran "Tom Waits" y nos regala este URBAN LIVE con más personalidad hasta la fecha.

Más:

Together

by Leandro Lucarella on 2010- 06- 13 18:54 (updated on 2010- 06- 13 18:54)
tagged 2010, album, en, music, the new pornographers, together - with 0 comment(s)

Together album cover

Solid new Album from The New Pornographers: Together. I will not say much more, if you now them, this new album won't disappoint you. If you don't know them, give them a try.

Probably my favourites are the catchy whistling of Crash Years, and the ballady My Shepherd.

How can you don't love FLOSS?

by Leandro Lucarella on 2010- 06- 12 00:11 (updated on 2010- 06- 12 00:11)
tagged en, floss, jabber, mcabber, migration, psi, python, script - with 0 comment(s)

Let me tell you my story.

I'm moving to a new jabber server, so I had to migrate my contacts. I have several jabber accounts, collected all over the years (I started using jabber a long time ago, around 2001 [1]; in that days ICQ interoperability was an issue =P), with a bunch of contacts each, so manual migration was out of the question.

First I thought "this is gonna get ugly" so I thought about using some XMPP Python library to do the work talking directly to the servers, but then I remember 2 key facts:

  1. I use Psi, which likes XML a lot, and it has a roster cache in a file.
  2. I use mcabber, which has a FIFO for injecting commands via the command line.

Having this two facts in mind, the migration was as easy as a less than 25 SLOC Python script, without any external dependencies (just Python stdlib):

import sys
import xml.etree.ElementTree as et

def ns(s):
        return '{http://psi-im.org/options}' + s

tree = et.parse(sys.argv[1])

accounts = tree.getroot()[0]

for account in accounts.getchildren():
        roster_cache = account.find(ns('roster-cache'))
        if roster_cache is None:
                continue
        for contact in roster_cache:
                name = contact.findtext(ns('name')).strip().encode('utf-8')
                jid = contact.findtext(ns('jid')).strip().encode('utf-8')
                print '/add', jid, name
                print '/roster search', jid
                g = contact.find(ns('groups')).findtext(ns('item'))
                if g is not None:
                        group = g.strip().encode('utf-8')
                        print '/move', group

Voilà!

Now all you have to do is know where your Psi accounts.xml file is (usually ~/.psi/profiles/<your_profile_name>/accounts.xml), and where your mcabber FIFO is (usually ~/.mcabber/mcabber.fifo, but maybe you have to configure mcabber first) and run:

python script.py /path/to/accounts.xml > /path/to/mcabber.fifo

You can omit the > /path/to/mcabber.fifo first if you have to take a peek at what mcabber commands will be executed, and if you are happy with the results run the full command to execute them.

The nice thing is it's very easy to customize if you have some notions of Python, for example, I didn't want to migrate one account; adding this line just below the for did the trick (the account is named Bad Account in the example):

if account.findtext(ns('name')).strip() == 'Bad Account':
        continue

Adding similar simple lines you can filter unwanted users, or groups, or whatever.

And all of this is thanks to:

Thank god for that!

[1]

A few people will be interested in this, but I think the ones that are will appreciate this link :) (in spanish):

http://www.lugmen.org.ar/pipermail/lug-org/2001-December/004482.html

Les Mentettes Orchestra @ Ciudad Emergente 2010

by Leandro Lucarella on 2010- 06- 08 23:56 (updated on 2010- 06- 08 23:56)
tagged 1/100s, 1/125s, 1/200s, 1/250s, 1/50s, 1/80s, 16.1 mm, 2010-06-02, 22.4 mm, 25.2 mm, 28.1 mm, 46.6 mm, 6.0 mm, 7.3 mm, 9.1 mm, canon powershot sx120 is, centro cultural recoleta, ciudad emergente, f/3.5, f/4.0, fluorescent, iso800, les mentettes, manual, orchestra, photo, pic - with 0 comment(s)

Les Mentettes, in Orchestra formation, at Ciudad Emergente 2010.

Excellent show, even when they clearly needed a little more space. =)

Les Mentettes Orchestra @ Ciudad Emergente 2010 (1)

Les Mentettes Orchestra @ Ciudad Emergente 2010 (1)

2010-06-02 19:02:31 ART
[ 1/250s f/3.5 iso800 16.1 mm Fluorescent Manual ]
Les Mentettes Orchestra @ Ciudad Emergente 2010 (2)

Les Mentettes Orchestra @ Ciudad Emergente 2010 (2)

2010-06-02 19:02:44 ART
[ 1/250s f/4.0 iso800 22.4 mm Fluorescent Manual ]
Les Mentettes Orchestra @ Ciudad Emergente 2010 (3)

Les Mentettes Orchestra @ Ciudad Emergente 2010 (3)

2010-06-02 19:04:31 ART
[ 1/125s f/3.5 iso800 9.1 mm Fluorescent Manual ]
Les Mentettes Orchestra @ Ciudad Emergente 2010 (4)

Les Mentettes Orchestra @ Ciudad Emergente 2010 (4)

2010-06-02 19:14:58 ART
[ 1/80s f/3.5 iso800 7.3 mm Fluorescent Manual ]
Les Mentettes Orchestra @ Ciudad Emergente 2010 (5)

Les Mentettes Orchestra @ Ciudad Emergente 2010 (5)

2010-06-02 19:20:00 ART
[ 1/125s f/4.0 iso800 46.6 mm Fluorescent Manual ]
Les Mentettes Orchestra @ Ciudad Emergente 2010 (6)

Les Mentettes Orchestra @ Ciudad Emergente 2010 (6)

2010-06-02 19:37:09 ART
[ 1/50s f/3.5 iso800 6.0 mm Fluorescent Manual ]
Les Mentettes Orchestra @ Ciudad Emergente 2010 (7)

Les Mentettes Orchestra @ Ciudad Emergente 2010 (7)

2010-06-02 19:41:23 ART
[ 1/200s f/4.0 iso800 25.2 mm Fluorescent Manual ]
Les Mentettes Orchestra @ Ciudad Emergente 2010 (8)

Les Mentettes Orchestra @ Ciudad Emergente 2010 (8)

2010-06-02 19:44:09 ART
[ 1/100s f/4.0 iso800 28.1 mm Fluorescent Manual ]
Les Mentettes Orchestra @ Ciudad Emergente 2010 (9)

Les Mentettes Orchestra @ Ciudad Emergente 2010 (9)

2010-06-02 19:44:39 ART
[ 1/100s f/4.0 iso800 28.1 mm Fluorescent Manual ]
Les Mentettes Orchestra @ Ciudad Emergente 2010 (10)

Les Mentettes Orchestra @ Ciudad Emergente 2010 (10)

2010-06-02 19:45:55 ART
[ 1/100s f/4.0 iso800 25.2 mm Fluorescent Manual ]

Release: Mutt with NNTP Debian package 1.5.20-8luca1

by Leandro Lucarella on 2010- 06- 07 02:12 (updated on 2010- 06- 07 02:12)
tagged debian, en, mutt, nntp, package, patch, release, ubuntu, vsevolod volkov - with 2 comment(s)

I've updated my Mutt Debian package with the NNTP patch to the latest Debian Mutt package.

If you have Debian testing/unstable and amd64 or i386 arch, just download and install the provided packages.

For other setups, here are the quick (copy&paste) instructions:

ver=1.5.20
deb_ver=$ver-8luca1
url=https://llucax.com.nyud.net/proj/mutt-nntp-debian/files/latest
wget $url/mutt_$deb_ver.dsc $url/mutt_$deb_ver.diff.gz \
   http://ftp.de.debian.org/debian/pool/main/m/mutt/mutt_$ver.orig.tar.gz
sudo apt-get build-dep mutt
dpkg-source -x mutt_$deb_ver.dsc
cd mutt-$ver
dpkg-buildpackage -rfakeroot
# install any missing packages reported by dpkg-buildpackage and try again
cd ..
sudo dpkg -i mutt_${deb_ver}_*.deb mutt-patched_${deb_ver}_*.deb

See the project page for more details.

Breathtaking Sculptures Made Out of A Single Paper Sheet

by Leandro Lucarella on 2010- 06- 03 22:50 (updated on 2010- 06- 04 04:17)
tagged art, en, es, paper, peter callesen, sculpture - with 2 comment(s)

What every programmer should know about memory

by Leandro Lucarella on 2010- 06- 01 23:53 (updated on 2010- 06- 01 23:53)
tagged book, cache, en, memory, programming, ulrich drepper, vm - with 0 comment(s)

This LWN large article looks like a very interesting read (specially for people like me that have a very vague idea about modern memory systems):

Ulrich Drepper recently approached us asking if we would be interested in publishing a lengthy document he had written on how memory and software interact. We did not have to look at the text for long to realize that it would be of interest to many LWN readers. Memory usage is often the determining factor in how software performs, but good information on how to avoid memory bottlenecks is hard to find. This series of articles should change that situation.

The original document prints out at over 100 pages. We will be splitting it into about seven segments, each run 1-2 weeks after its predecessor. Once the entire series is out, Ulrich will be releasing the full text.

The full paper in PDF format is also available.

RSS feed (and other problems) fixed

by Leandro Lucarella on 2010- 06- 01 00:08 (updated on 2010- 06- 01 00:08)
tagged en, feed, fix, rss, self - with 0 comment(s)

After moving my home page (and this blog) from home to a proper (VPS) hosting, there were some problems because I have to migrate from Apache to LIGHTTPD.

The RSS feed was affected, so if you read this blog using an aggregator, you probably didn't received any updates in the last weeks. I also fixed some other problems that made the feed not W3C valid. Fortunately now it is. =)