Rainwatch featured on Android Market

Posted by – 2010/09/09

Sometime yesterday my app Rainwatch was added to the “top free” list on the Android Marketplace, showing in 5th position in the News and Weather section. This is strange because it’s only 32nd in the “top free” list on the market on Android devices, but hey, I’m not complaining!

I guess I’d better make a promotional image for Market and update the screenshots so they actually look like recent versions of the app!

Float.parseFloat is slow

Posted by – 2010/08/27

While profiling some loader code and expecting to see performance issues with my regular expressions, I found that ~60% of my time was actually spent converting String variables to floats. It turns out that the slow bit lives inside Float.parseFloat, where it calls String.toLowerCase every single time just in case this string is a hex float, a very rare type of float which I had never seen before. I logged this with Apache, but as I can’t ship a custom ROM with my SVG parser I decided to replace it.
Here’s the results from some tests of 3896 calls to parseFloat on my Nexus One:

  • a) Using Float.parseFloat(String): 1516.449ms
  • b) My own parseFloat(String): 654.882ms
  • c) …and my own isDigit(char): 449.622
  • d) …and isDigit written inline: 295.865ms
  • e) …copying the string into a char buffer and avoiding all string access and method calls: 254.527ms (112ms spent copying the characters!)

So in theory, if the method took a character buffer and length it could be as short as 135ms, over ten times faster than Float.parseFloat. I’m currently using option d as gives a nice performance gain without breaking my design, but when performance tuning the entire API later this may see some huge changes. Here’s the function I cooked up:

public static float parseFloat(String f) {
	final int len   = f.length();
	float     ret   = 0f;         // return value
	int       pos   = 0;          // read pointer position
	int       part  = 0;          // the current part (int, float and sci parts of the number)
	boolean   neg   = false;      // true if part is a negative number
 
	// find start
	while (pos < len && (f.charAt(pos) < '0' || f.charAt(pos) > '9') && f.charAt(pos) != '-' && f.charAt(pos) != '.')
		pos++;
 
	// sign
	if (f.charAt(pos) == '-') { 
		neg = true; 
		pos++; 
	}
 
	// integer part
	while (pos < len && !(f.charAt(pos) > '9' || f.charAt(pos) < '0'))
		part = part*10 + (f.charAt(pos++) - '0');
	ret = neg ? (float)(part*-1) : (float)part;
 
	// float part
	if (pos < len && f.charAt(pos) == '.') {
		pos++;
		int mul = 1;
		part = 0;
		while (pos < len && !(f.charAt(pos) > '9' || f.charAt(pos) < '0')) {
			part = part*10 + (f.charAt(pos) - '0'); 
			mul*=10; pos++;
		}
		ret = neg ? ret - (float)part / (float)mul : ret + (float)part / (float)mul;
	}
 
	// scientific part
	if (pos < len && (f.charAt(pos) == 'e' || f.charAt(pos) == 'E')) {
		pos++;
		neg = (f.charAt(pos) == '-'); pos++;
		part = 0;
		while (pos < len && !(f.charAt(pos) > '9' || f.charAt(pos) < '0')) {
			part = part*10 + (f.charAt(pos++) - '0'); 
		}
		if (neg)
			ret = ret / (float)Math.pow(10, part);
		else
			ret = ret * (float)Math.pow(10, part);
	}	
	return ret;
}

This is of course a very crude method, it requires a well-formed number and will return 0 or partial numbers instead of raising exceptions, it doesn’t work with hex floats or parse NaNs or Infinity and it doesn’t use doubles internally so the accuracy is not perfect. It does however work for my purposes, so I thought I’d share it with the Internet.

Microphone for Android

Posted by – 2010/08/22

So, my 4th Android app is out, a simple mic which you can plug into your computer. It’s got quite a slating on the Android Market because of its latency, the problem is that there’s quite large minimum values on the buffer size for accessing input and output buffers, there’s no way to reduce this latency below the ~300ms which it currently has. Hopefully AOSP will address this eventually, paving way for realtime audio applications.

Adventures in Android

Posted by – 2010/08/17

Since getting myself a Google Nexus One I’ve decided to do a bit of Android development. My first impressions with the platform weren’t really that good, but I’m beginning to get the hang of it now.

My main problem is that Java is a horribly verbose and restrictive language. To do the simplest things you need to implement at least three interfaces and extend a couple of abstract classes (after reading the documentation for each of them and their alternatives of course). Something which could be written in Python in three lines of code and two minutes takes fifty lines and twenty minutes in Java. Perhaps that’s just me, maybe I’ve been spoiled by dynamic languages and expect to be able to do things a hundred different ways by just typing whatever comes to mind, rather than carefully considering the available options and planning every step of my app. In my short journey through Java development I’ve suffered a lot of pain because I make assumptions and choose a design pattern which is incompatible some point later down the line, so I end up refactoring everything ten times before I even get a working prototype. I’m slowly learning not to fly by the seat of my pants (even if it is the most fun way to fly) and perhaps that’s a good thing.

My other gripe is the UI editor and XML format, their steep learning curve makes the design stage a huge time sink. I’ve now spent a fair bit of time banging my head off my keyboard while attempting to make the simplest of interface, which still don’t look like they do on paper, but I think I’m getting the hang of it.

Anyhow, so far I’ve managed to knock out 3 applications which are available in the Android marketplace:

Anonypic

This little app just adds an extra option to your share menu, and will upload an image to bayimg.com, the anonymous image sharing service by the creators of The Pirate Bay. Images have their EXIF data removed, so you can share images without leaving a trail of metadata leading back to your phone.

Rainwatch

Rainwatch is an alternative viewer for the BBC’s Maps Presenter, the Flash application available on their weather site. It’s far from complete but is good enough to predict the weather, so I’m quite happy with it (as are my 1500 active users)

MC Mail

MC Mail, or Missed Call Mailer is a little app which sends you an email when you get a missed call. The back-end is written in PHP and MySQL, the front-end is mostly just a service which monitors your call log. Useful if you’re a hospital or call centre worker who has access to email but can’t use a phone in work, or if you always forget your phone. It usually only works while the phone is in silent mode.

Next steps?

I’ll make a couple more apps and maybe a game, then learn the Native Development Kit and port Irrlicht using Christian’s OpenGL ES driver. I haven’t done any Irrlicht code in ages, so that’s certainly on the agenda.

Flattr

Posted by – 2010/08/14

Now that Flattr is finally in public beta, I’ve decided to sign up and pledge the minimum possible payment, a measly €2 a month. Now all I need to do is actually find some sites to donate to!

I’m kind of torn about adding Flattr links to my projects, on one hand I want to encourage the uptake by being another site which supports Flattr, on the other hand I don’t want to whore myself out for a few pence.

So at some point I’ll add Flattr links to the free Android apps which I’ve made, which will feature in the menu at the top shortly.

JPerfmeter crashes while starting

Posted by – 2010/05/17

I’ve been us JPerfmeter in work to keep an eye on Linux system counters served up over rstatd.

However, it has one very annoying bug:

If one of your servers goes offline, or it somehow lets you add a server which doesn’t exist JPerfmeter will crash and refuse to start again. The setting is saved somewhere on disk. Where? Google didn’t know (hence this blog post).

Half an hour of messing around in Procmon going through reams of logs and I find the settings in %userprofile%\JPerfmeter, just where you’d expect them to be. facepalm.jpg

Automatic favicon to PNG script

Posted by – 2010/05/16

Ever want to add a link to a site with the favourites icon in the page along with the link? I did, so I made this cool little toy:

http://favicon.bitplane.net/

read more…

code_swarm

Posted by – 2010/02/14

I’ve been playing with code_swarm and made this video of the Irrlicht Engine’s development history:

Since the video is generated from the SVN version history it starts at the point where Niko gave hybrid and I SVN access (June 2006), so misses out years of development leading up to the 1.0 release.

code_swarm is a really cool tool, one thing which is exciting is the fact it supports MediaWiki. It would be really nice to show a small wiki coming together.. or maybe one day Wikipedia’s entire changelog (we can dream!)

My first ascension!

Posted by – 2010/01/21

After playing nethack for about three years, bitplane the wizard finally ascended to the status of Demigod.
Nethack is by far the most difficult yet addictive game I have ever played and although I rate it highly, I don’t recommend it unless you’re a glutton for punishment.
My three year addiction isn’t over yet, I think I’ll play another role next time I have a spare few.. uh.. days.

Website update

Posted by – 2009/12/30

I’ve finally got around to editing the Simplish template and adding pages for some of my old software projects. There’s some links at the top up there, hover over them and you get a nice drop-down menu with a list of projects.

The meat of this is JavaScript stolen from another theme and some PHP code gratuitously pasted into my header, this isn’t IP theft, and not just because it’s the season of sharing! This is what’s great about free software licenses.