My blog has been moved to ariya.ofilabs.com.

Friday, September 11, 2009

SVG: parsing and content optimization

A few weeks ago, just for a change (between the usual QtWebKit bug-fixing and patches juggling), I did take a look at our QtSvg module. According to some internal reports, QtSvg is not fast enough when parsing a large and complicated SVG. Of course, slow is relative, slow to what. And arguably, parsing time is not as important as rendering time. But if you stash your user-interface elements in some sort of SVG theme, loading time becomes a factor (caching the pixmaps whenever possible also helps). Of course, reduced size served in a web server can decrease the bandwidth as well (think of all the SVGs in Wikipedia).

Still, I decided to have a look, just in case there are low-hanging fruits I can grab. And I was right, far from being an SVG expert, with just two days of work I managed to squeeze its performance a bit, which you'd enjoy already in the recent 4.6 preview.

The chart above - shorter is better - represents the comparison of the time spent in QSvgRenderer::load(), measured using CPU tick counter (in millions of ticks), comparing Qt 4.5 and 4.6. I also tested some other files as well, see the bigger bar charts. In all measurements, the 95% confidence intervals were well below 1%. In-house Theme refers to an internal SVG that unfortunately I can't share. Tiger is the SVG version of the famous head in PostScript (taken from GNU GhostScript), something I have shown before. Imperial Coat of Arms of France is another complex SVG, from Wikipedia Commons. World Map is the public domain blank grayscale world map from Wikipedia. There are a bunch of other test files I used, they mostly show the same improvements.

As you can see, Qt 4.6 would enjoy a bit of speed-up (in some cases up to 1.4x) when loading and parsing SVG.

However, I did not stop there. For the fun of it, I quickly hacked a Qt-based, command line SVG minifier, dubbed SVGMin. More about it can be read in the detailed Quick Start, but basically it tries to eliminate redundant garbages which have no effect whatsoever in the final rendering.

What follows is the chart showing the same type of measurement but I added the result with the minified SVG (see also the full comparison chart). The result should speak for itself:

I plan some more improvements to the SVG minifier, for example collapsing a single grouped element (<g><path ...></g> makes no sense), group a bunch of nodes with similar attributes (no need to duplicate the same fill colors over 100 circles), remove useless attributes (why there is fill-* for fill:none?), and many others. Hold your breath.

Tuesday, September 08, 2009

the game of escalation

img_0086

Often I ask myself how long I would still want to stay in the software industry. Before I started my professional programming career, I never thought that this wonderful world of software craftsmanship is full of complaints, frustration, anger, and hostility. Perhaps that is just the reflection of people wanting to achieve the best things they can do. When you aim for a perfection, anything good enough will not be satisfactory.

I can't say for sure, but somehow I feel that I am still heavily influenced by the positive gratitude mentality, even in the case of calamity. When you have an accident and your right arm is amputated, someone reminds you, "You are lucky, you could have lost your legs!". Losing an arm is considered lucky? This does not mean that we bury our head in the sand and forget the fact that one arm is gone already, it just means that we should not be blind to the fact that things could have been worse. By doing so hopefully we keep things in perspective and move forwards as positive and as best as we can.

One of the lessons I learned so far is the amount of extrapolated verdicts you would get from the users, the developers, and/or the customers. Any bugs, any annoyances, no matter how small it is, are sometimes blown out of proportion. I call this the Universal Rule of Blaming. A customer complains, the company desperately grabs a consultant to help, he finds the bug in the toolkit, the toolkit guy chains it further to the operating systems, and so on. Of course, for each stage, the amount of anger and loudness of the screams increase exponentially. Basically, nobody wants to be the escape goat.

Sadly, everyone in the business of doing software seems to forget that making a software is just like another engineering project. It has its constraints, the resources are limited, the time is the (common) enemy, priorities must be set, and practically it is impossible to achieve 100% perfectness. It is the classic optimization problems. Thus, the responsible people have to make some decisions and these decisions can't please everyone. There will be people alienated with such decisions. Anyone ever done any kind of sensible business knows exactly what it does mean. Every customer feels that he is important (I mean, who does not?), yet a typical company has a lot of customers and such a company is always ready to disappoints 10% of the customers, rather than 90%. As you can guess, it is a matter of minimizing the loss. When a business guy asks his customers, "Hey, I need your feedback" and he really means it, he is not trying to be nice, he is trying to save his business.

However, my concern is not on the technical matters, but rather the non-technical side. When you are angry, you may say some words that you may regret later. Unfortunately, getting mad because of software annoyances can trap you in the same, if not worse, situation. What I often witness is that people start guessing, accusing, throwing blames, up to the a point where it becomes counter-productive and getting personal. You all know what happens when a developer takes it personally: a cycle of violence is about to roll. Once a while I try to stand in the line of fire (a big mistake, I know) in order to bridge both parties. No luck, it is like being trapped in a DMZ and people will just release their steam and waste their bullets to me as if they are happy to find a new bandito to kill. Ever wonder why some developers take the holy vow of silence?

The most common case is the why-my-bug-is-not-fixed drama. For example if I do not fix the problem X on the platform Y, people might start rambling on anything from "you secretly plan to drop support for Y" to "you rather focus only on feature Z instead of fixing X". There are various reasons I still do not manage to provide you the fix, but because of the frustration, people tend to invent and believe in some kind of conspiracy theory. Feel free to write a long Pulitzer-quality editorial on why the lack of the fix destroys your million dollar business, but no need to cross the line and start imagining things.

The drama can continue in a developer conference, where a guy might ask a simple, seemingly innocent question (even in a keynote speech) such as "Why don't you fix (my) bug 123? Why do you work on feature 456 instead?". Believe me, I saw that happened many many time. Those questions will put both the speaker and the audience in a awkward situation. While I fully agree that every bugs must be fixed, throwing such a question which only has the intention of embarrassing the developer in front of everyone is way too dirty for my taste (not to mention that, like often the case, our poor little developer never took any How to Deal with Angry Customers course). In fact, every time I encounter this kind of scene, I make a mental note to stay away from that guy. And I am sure I am not the only one who is doing that. Like I often expressed, we are not in the kindergarten anymore, screaming does not make the solution comes faster. Time to make a ThinkGeek T-shirt for that?

Thus, I reached a conclusion that there are two types of software guys: those who symphatize with the difficulties and problems of delivering a perfect product (because they are trying to do the same, "Welcome to the club!") and those who just like to shift the blames to others (because they get customers banging their doors). Nobody likes to deal with angry customers so the choice is (not) hard: either you take the blame (after all, you are the one who is doing the direct business to your customers) or you pass it along (every one of us is a customer of someone else's product). In the latter case, you just become yet another angry customer.

Noblesse oblige.

Tuesday, September 01, 2009

wanna curve away? it's such a perfect day

If you were at my Special F/X talk, Desktop Summit in Las Palmas, or if you watched the recorded video (135 MB Ogg), you might notice the tongue-in-cheek gratitudes to Lufthansa dan SpanAir I expressed at the beginning of the talk. The story goes as follows. As all of us, the Trolls, left Oslo to fly to Las Palmas, our flight got delayed twice, in Oslo (by Lufthansa) and Madrid (by SpanAir). Like every other dedicated (read: foolish) hackers, I took advantage of the delay to fulfill my dream (read: obsession): writing my own presentation tool. Hence, the special thanks.

Presentation

Of course, like every other dedicated hackers, I cheated (after all, great artists steal). Inspired from the previous discussion with Simon (and Holger), I just took S5 and wrapped it with QtWebKit. The result is something I called s5runner. The 200-lines Qt/C++ code (and PyQt, thanks to David) is best demonstrated by watching the following short screencast:

Few extra features added on top S5 are screen blanking (white or black), night mode (just for the fun of it), syntax highlighting (useful for code snippet), countdown timer (because my laptop has 100x computing power vs my wristwatch), and (my favorite) live editing.

I will definitely reuse this for my upcoming talks.

Sunday, August 30, 2009

light beams

light attractions

Some kind of midnight light attractions a week ago in Bremen was a good opportunity, a better one than just in the physics class, to remember that light beams are actually invisible, except when the beams get scattered by some particles or other objects. Hence the fog machines operating in the same space and time as the powerful headlights.

Friday, August 28, 2009

mails I wish I could skip

posten

Don't get me wrong, I love to get emails. In fact, as long as the emails are not nuked by the spam filter, I read each and every one of them. I might not give a response immediately, but I seldom skip an email. However, there are few types of e-mails that I wish I could just skip, thereby saving my and the everyone else's time.

that starts with "Dear Sir/Madam". Nothing wrong with it of course. But if someone knows my email address, a little check with Google would reveal my gender and my full name. However, with that Sir/Madam thing, I cast a suspicion upon the content of the email (likely a spam anyway).

that asks "how to download FooBar". Maybe s/he reads one of my articles or a post in my blog. But normally I always state the web site of that particularly interesting program so that people can try it. Usually I give her/him the benefit of doubt and send the first few links I find by googling (or lmgify-ing) on "download FooBar".

that only says "I tried to do X and it did not work". Unless I have a crystal ball, how on earth could I possibly know the problems? Shall I forward this email to Uri Geller, or any of his successors, then?

that requests suggestions for a (final) project. If I do not know the sender (what s/he's studying, what the interests are, etc), well what would I say then? I can mention anything, e.g. create a rocket that flies us to Jupiter, but that wastes more of our time.

that ends with "Please help, it's urgent" or something similar. As much as I would like to help, I also have a life, and I have my own sets of problems, too. And so does everyone else. True, urgency requires a delicate handling but I am not in business of waving a magic hand. Beside, we are not in the kindergarten anymore, screaming does not make the solution comes faster.

that asks for some architectural diagram of my example code. It's soooo "corporate". Seriously, do you expect me to fire up Rational Rose and draw colorful charts (flying arrows included) for a 300-lines example program? Some people fail to see that an example, just as the name implies, is meant to be taken as an example.

that is closed with a very long signature. It's fine for the legalese purpose, but isn't it ironic when the mail signature is ridiculously long, sometimes up to 4x longer, than the content of the mail itself? And when the email is basically a set of some of the points above, the signature is like adding an insult (a terrible one even) to the injury.

Do you ever get other types of annoyances like that?

Thursday, August 27, 2009

Nokia N900: Linux-based mobile phone

Finally it's out. N900 is the first Linux-based 3G/HSPA phone from Nokia, powered by Maemo. There are already some high-quality awesome pictures of the phone, or just enjoy the following taken by my countryman who is working for Maemo. Or watch its 75-second promo video clip. Price is not set yet, but seems to be in the EUR 500 range. The geek side of you might want to glance at the specifications (and mark that OpenGL ES 2.0!).


Monday, August 24, 2009

oslo mela

Food

Just like last year, Oslo Mela Festival few days ago was something we did not miss, in particular because of the food.

Thursday, August 20, 2009

q-o-t-w

People who succeed in life are rarely reflective. Their gaze is always on the future: that's why they succeed.

-- "Ghost", Robert Harris

Tuesday, August 11, 2009

(again) the map of my world gets smaller as I sit here

I always wanted to help Marble, but I am guilty because until now I can't afford any time to play with it. All these years, I used to compile bleeding-edge Marble from time and time, use it, and basically that is it. Although since a long time ago I promised Torsten that I was willing to help Marble, actually only right after Gran Canaria Desktop Summit finally I devoted some time to study its code. The three of us, Torsten, Andrew and I also had a short but fascinating discussion during the summit.

Now, I still don't manage to contribute anything to Marble yet, but I already have something in my pipeline. You will likely hear from me in the coming weeks, so stay tuned.

Since I reckon I enter the wonderful territory of mapping world, I thought, well, let's familiarize myself a bit with the technology. I took a look at the interesting experimental Google Maps API v3 (which BTW does not require an API key). Using QtWebKit, I wrote a simple 300-lines example that shows a magnifying glass over the map (see the screencast). Of course, the area under is the zoomed version of the map.

Since I am flirting with Qt for S60 these days, I thought about bringing that example to the phone. However, instead of relying on Google Maps, I decided to leave the dark side and jumped to use OpenStreetMap instead. The result is effectively an example of how to render the tiles from OpenStreetMap using Qt, which also runs on S60. It does even have the night-mode feature.

Video, you asked? Thanks to Alessandro, here is the 52-second videocast that demonstrates it (or watch on YouTube), running on Nokia 5800:

Sunday, August 09, 2009

how far is that plane

This did happen in my last flight. I consider making it a quick math quiz for any candidate I have to interview in the future (to see whether it takes him 5 minutes or 5 hours to analyze).

A few minutes after the captain announced that we were flying at forty thousand feet above the sea level, cruising at the speed of 900 km/h, through the window we saw another airplane flying at roughly the opposite direction, but at a slightly lower altitude. Of course, the obvious question was asked: How far is the other plane from us? This is better than the typical Fermi problem. Assuming that that airplane was visible in our 90 degrees field of view for 4 seconds and it flew just as fast as our plane, I did a quick calculation and came up with an answer, the flight trajectory of that plane was 1 km apart from ours.

The other guy was impressed, but he was not convinced. Now, since my math skills are rusty, I am sure I missed a thing or two. Now, what is your take?

(Picture rendered from Jarno's public-domain vectorized aircraft).

Saturday, August 08, 2009

the power of definition

Have you ever got a simple question from a non-techie person, like "What is Java"?

Here is a portion of what you get from wikipedia on Java:

Java refers to a number of computer software products and specifications from Sun Microsystems that together provide a system for developing application software and deploying it in a cross-platform environment

Here is what you'd enjoy from its official site:

Java allows you to play online games, chat with people around the world, calculate your mortgage interest, and view images in 3D, just to name a few.

That really makes my day.