One of the standard objections to the Palm operating system is that it isn't multi-tasking.
That's sort-of true, but you wouldn't know it when you were surfing the web whilst listening to an mp3 and using another application in the background to make your volume keys act as scroll keys.
This article will explain the basics about how that all works, and how you can use Palm Internals to see how much this background activity is slowing down your Treo/Centro - and what you can do about it!
So how does stuff work in the background?
Palm OS has two main ways of making stuff happen in the background. The first is specially designed for sound. It lets Pocket Tunes and Aero Player run merrily in the background. It actually doesn't have to be used for sound - in fact, I think it's used for checking email by at least one application.
We're going to ignore the sound thread method though because the vast majority of applications that work in the background use notifications. The Notification system lets applications register with the operating system for things they care about.
One of the notifications that Butler registers for is 'hapl' also known as sysNotifyAppLaunchingEvent. This is the notification for when an application is about to be launched. Whenever the system is about to launch an application, it first 'notifies' Butler that it is about to. Butler can then do anything it needs to (like keeping a list of recently opened applications).
To the user, it seems as if this is happening magically in the background, but actually, while this notification is being processed by Butler, the system waits, so there is a tiny and hopefully unnoticeable delay.
There are lots of different notifications that applications can register for. You'll be amazed at how many are live on your Treo. You can see them all by downloading the free Palm Internals, letting it scan your treo/centro and tapping on the 'Notif.' button.
My Treo 650 lists 220 notifications that are live! Part of the list is shown here:

For many of the standard notifications, Palm Internals gives an explanation, like 'hots' which is sent when a hotsync starts. I've made a list at the bottom of this article of some of the others. There is some great programmer humour in some of these!
Now, every time one of these happens, each registered application is called and given a chance to do something. Most of the registrations are actually for system processes like the bluetooth manager, the GSM library or the SMS application. (if you want to see the whole list, use menu/Full Notif).
Most notifications happen fairly infrequently (how often to you actually switch apps or insert an sd card), so it doesn't really matter whether the application responding takes a thousandth of a second, or a tenth of a second. Even an extra tenth of a second (that would be REALLY SLOW) isn't going to make a difference to how fast your device feels. One notification is different though!
'HEDE' - Take Heed!
This is the notification of notifications! Palm has this warning for developers:
"Be very careful about registering for this; you can easily impact performance (in a bad way!)"
This notification is sent for every single event that the device handles. This doesn't mean much until you know how many events are sent! When you launch an application, the following events get sent:
- sysPenDown
- sysAppStop
- frmLoad
- frmOpen
- sysWinEnter
- sysPenUp
Whenever you press a key, at least two events are sent (one for the key down, one for the key up).
This means that when you launch an application, Butler is called 6 times! When you press a key, Butler is called twice. Butler has to finish its work before the application you are trying to launch gets a look in!
Unfortunately, HEDE is the only way that developers can get notifications of key presses, so quite a few apps register for it. As you can see though, it's vitally important that if an application registers for HEDE, it makes every effort to be as efficient as possible.
The slow way and the fast way.
There are two ways that an application can register for a notification. Normally, the slow way is the best!
The Slow Way
When an application registers the slow way, it just tells the system what its creator id is. When the notification is triggered, the following happens:
- The system goes looking for the app that matches the creator id
- The system loads the application into cache (if necessary)
- The system calls the application's main function
- The application recognises that this is a notification launch and calls the function that does the actual work
The great advantage of this method is that the system worries about 1 & 2. It means that the application doesn't even have to know about caching and the weird stuff that the new palms get up to!
For almost all notifications, the slow way is the best way.
The Fast Way
When an application registers the fast way, it just tells the where the function is that needs to do the work. When the notification is triggered, the following happens:
- The system calls the function that does the actual work
For HEDE, this is almost certainly the right thing to do. It is about 15 times faster than the slow way.
WARNING: The fast way has many pitfalls! The main one relates to the cache system in newer palm devices. In the old days, you could tell the operating system where your function was and expect it to still be there when it was needed. Now days, if you're not very careful, the operating system can sweep your function out of the cache. The next time that the notification calls your function, it might actually be trying to run a bitmap, or your latest email. The odds are that it isn't going to work! Your Treo/Centro will crash unexpectedly and with a quite unhelpful error log. My next article will explain how to use Reset Doctor to investigate which applications might be causing this.
Benchmarking
Now you know what is going on, you can check which applications are registering for HEDE. Using Palm Internals' speed checker, you can even do a speed test to do a very rough check on the speed impact.
Simply select Menu/More/Speed Test, sit back for a moment and you'll get a result. What Palm Internals does is simulate 10,000 key presses and see how long it takes. This isn't like 'real life' because it isn't testing how quickly the notification handles all the other types of events that get sent with HEDE, but it's not a bad proxy.
My result is:
"Time in tics 4562, time in secs 45" (there are 100 tics in a second).
I can see from my notification list above that Butler and ScreenShot5 are registered for HEDE. You'll see that Butler has m68k... after it. This means that it is registered the fast way. ScreenShot5 is registered the slow way. If I disable ScreenShot5, my result is:
"Time in tics 393, time in secs 4"
That's a big difference! All I need to do now is get my thumb-typing rate up to 10,000 chars/minute to take advantage of the benefit! If I disable Butler, I get
"Time in tics 111, time in secs 1 "
That's a much smaller difference - which is because I take pride in keeping Butler fast!
I've done a little testing on some common applications. On my Treo 650, they add the following amounts to the speed test:
| Application |
Delay Tics |
Delay Secs |
| Butler |
282 |
3 |
| Initiate |
85 |
1 |
| KeyCaps 650 |
4646 |
46 |
| ScreenShot5 |
4451 |
44 |
| TreoSelecText |
3066 |
30 |
| Tech Sounds |
5108 |
51 |
Keep Your Perspective!
We all love to optimise - but remember it matters not one jot how slow the test is.
The only important thing is whether your device feels slow. If you have a lot of apps registering for HEDE the slow way, it might be a problem. One or two probably won't be noticeable.
I keep Butler, Initiate and ScreenShot5 enabled all the time. I could significantly improve my test score by disabling ScreenShot5, but my Treo 650 seems perfectly speedy and I like the app! If it saves me 15 seconds from having to open it, enable it and disable it whenever I want to use it, then that's worth a lot more than the odd hundredth of a second that I can't even notice!
My next article will be on the cache and how registering for notifications the fast way can cause random instability!
If there are other 'Inside your Treo' topics that you'd like me to cover, please let me know at the Hobbyist Software forum.
Some notifications
| Notification |
Meaning (when it is sent) |
| 'sync' |
Sent at the end of a hotsync. |
| 'bozo' |
When the user presses the 'Forgotten Password' button in the security app, just before every database's private records are deleted. |
| 'worm' |
Immediately after the device wakes up |
| 'lazy' |
Broadcast a little later when the device is fully woken up |
| 'volm' |
When a vfs volume is mounted (sd card inserted) |
| 'volu' |
When a vfs volume is unmounted (sd card removed) |
| 'attn' |
Attention manager just got users attention |
| '-pdb' |
Protected database is about to be deleted |
| 'hvch' |
Sent when a virtual character is about to be processed (like one of the hard keys) |
| 'hede' |
Sent when any event is about to be processed |
| 'hapl' |
Application about to be launched normally |
| 'hapq' |
Application about to quit |
| 'bsbc' |
Battery state has changed |
| 'hpps' |
A pen stroke on the screen has started |
| 'scrs' |
Pen input area has opened or closed (DIA area) |
|