Saturday, January 21, 2017

The first performance issue I've fixed

The first performance problem I've found and fixed in code written by someone else was in Gadu-Gadu. GG was an Windows instant messenger very popular in Poland in the early 2000s. It was closed, binary-only code but due to its popularity a modding "underground" has been formed quickly and soon, its protocol was reverse engineered.

I was about 18 years old at the time and I had a running competition with a friend to make our Windows systems look and feel like Amiga OS. We had the basic things covered, but some programs were not themeable at the time. GG was one of them and I thought: challenge accepted.

I decided to use PowerGG, a live patching framework by Ajron. I've quickly found out that the conversations were displayed in an embedded Internet Explorer control and were plain old HTML + Javascript. Then I've found a way to patch that HTML code and it looked just like Amiga.

GG always had this annoying bug that the longer your conversation was the slower the program was. And boy, our conversations were long these days, we were teens and had lots of time on our hands. Sometimes we talked so much that the program froze for several seconds after I pressed Enter.

After looking at the Javascript code it quickly became obvious why this is happening: GG was looking for a <div> containing the last message, and then appended the new message after that <div>. But instead of getting the number of <div>s and finding the last one, it iterated over all of them. And, since these were days long before the V8 engine, Javascript wasn't very fast on 400 MHz CPUs and iterating several hundred DOM elements took a lot of time. It was a three-line code change and it made the messages send instantly.

If you want to verify my story. the PowerGG plugin was briefly named "Amigo" and then released as "Foolteen".

No comments:

Post a Comment