Tarik Al Hadethi Download CV

A comment that was wrong in both halves

Clarus saved screenshots about twenty times larger than they needed to be, for ten weeks, guarded by a comment explaining why that was the right trade. Both halves of the comment were false.

The screenshot save path encoded PNG with CompressionType::Fast and FilterType::NoFilter. Its own doc comment justified the choice: it gave up “a ~20-50% smaller file” in exchange for encode speed.

That is a reasonable trade to make in a screenshot tool, which is presumably why nobody, including me, ever questioned it.

Measuring instead of reading

I wrote a small harness that ran the real encoder over a capture Clarus itself had written, rather than a synthetic image:

287x107 screenshot        size        encode
Fast + NoFilter (was)   106.18 KB     0.2 ms
Fast + Adaptive          14.07 KB     0.1 ms
Default + Adaptive        4.92 KB     0.5 ms
Best + Adaptive           4.72 KB     3.5 ms

The second row is the one that matters. Adaptive filtering was smaller and faster. Not a trade at all: the setting we shipped was worse on both axes it claimed to balance. The comment described a compromise that did not exist.

And the size claim was not off by a bit. It said 20-50%. The real figure between the shipped setting and the one now in place is about twenty times.

Proving the number was really ours

A benchmark on a hand-picked image proves nothing about what users have on disk, so the check was this: take a screenshot the app had already saved, and re-encode it with the old settings.

The file on disk was 108,729 bytes. Re-encoding produced 108,729 bytes. Byte for byte, which means the numbers above describe the real output rather than a lab condition.

One more number puts it in perspective. A 287×107 RGBA image is 122,836 bytes completely uncompressed. The shipped setting was storing screenshots at 88% of raw. It was barely compressing at all.

Why it survived so long

Because the comment answered the question. Anyone reading that code, including me on several passes, saw a decision that had already been considered and moved on. A bare CompressionType::Fast with no explanation would have invited a second look. The explanation is what made it invisible.

A comment is a claim about the code. It is not evidence, and it does not decay visibly when it stops being true.

What I would have needed to catch it earlier is not more careful reading. It is the habit of putting a number next to the claim: the harness took twenty minutes and it is now part of the repo, so the next person to change those settings gets an actual measurement rather than a sentence.

Screenshots now save at 4.92 KB instead of 106 KB, and encode in half a millisecond.

Written while building Clarus.  ·  More writing