Search
Enter Keywords:
Home
Reducing CPU Use by OS X's World Clock Dashboard Widget PDF Print E-mail
User Rating: / 1
PoorBest 
Written by Michael Salsbury   
Thursday, 22 September 2005
As discussed in another article on this web site, the OS X World Clock Dashboard widget can become a severe drain on system resources if it's left active on the screen for long periods of time since the last reboot.  Even when it has just been started up on a freshly rebooted system, it uses quite a bit of CPU.

For example, here's what Activity Monitor showed me when I launched the World Clock Widget on a 933 MHz G4 running MacOS X 10.4.2:



As you can see, CPU usage is in the 7-10% range.  If left on screen long enough, it will grow to as much as 80-85% of the CPU while it's active (0% when not shown on screen).  It will also consume quite a bit of RAM, potentially all the RAM on the system.

If you make the changes I'm going to suggest below, you can reduce that CPU usage considerably (though the Widget will still gradually increase its CPU and RAM usage over time for reasons I haven't figured out).  The Activity Monitor image below is what resource consumption looks like on the modified World Clock:



The first "World Clock DashboardClient" process above is mine (the one that's using 1.30% of the CPU).  The second "World Clock DashboardClient" process is an unchanged OS X 10.4 World Clock widget that has been left running on-screen for the better part of 4 days.  As you can see, it's grabbed about 80% of the CPU, 200MB of RAM, and 350MB of virtual memory.  My modified client (which hasn't been running very long) is using a lot less CPU and RAM (though it shares whatever is wrong in the unmodified widget that increases CPU and RAM usage over time - but it seems not to consume them as quickly).

My changes reduce CPU consumption from 7-8% down to about 1.2%.  You still have a second-hand, but you are eliminating the "sweep" (or "wiggle") the second-hand does as it revolves around the clock.  Apparently that sweeping action increases the widget's CPU usage by around 600%.  (Making it a good example of why I hate little utilities that do cutesy graphical changes to the system or OS features that waste lots of CPU just to animate things.)


Making the Change

Here's how to make the changes I suggest that will greatly reduce the CPU consumption of the World Clock Dashboard Widget in OS X 10.4.2 (and earlier 10.4 releases). 

First, login as "root" or "admin" as you will need to be able to modify files that are "owned" by the operating system.

In the Finder, locate the folder at "/Library/Widgets".  Within that folder, locate the "World Clock" widget.  Right-click on it (if you have a two-button mouse) or control-click on it (if you don't have a two button mouse) to bring up a context menu.  Choose the "Show Package Contents" function in the menu.  You should see a list of files.  One of these is "WorldClock.js".  Copy that file to somewhere else on the disk.  (It is also a good idea to put another copy somewhere else so you can return to the original one if you need to!)  Open that file with TextEdit (recommended, but you can use anything that will open the file as text and allow you to save it back as text without formatting).

Under the Edit menu in Text Edit, do a Find for "function secondSweepbackAnimate()".  This should bring you to a function that looks like the following:

function secondSweepbackAnimate()
{
        if ( secondSweepbackAnimation.step >= secondsSweepbackAmounts.length )
        {
                //  no more steps to the animation, so clear the timer
                clearInterval(secondSweepbackAnimation.timer);
                secondSweepbackAnimation.timer = null;
                secondSweepbackAnimation.step = 0;        
** snip ***
                secondSweepbackAnimation.step++;
        }
}

Comment out (i.e., disable) all the lines in the function code except for the following:

                clearInterval(secondSweepbackAnimation.timer);
                secondSweepbackAnimation.timer = null;
                secondSweepbackAnimation.step = 0;        

This should leave you with only the following lines NOT commented:

function secondSweepbackAnimate()
{
                clearInterval(secondSweepbackAnimation.timer);
                secondSweepbackAnimation.timer = null;
                secondSweepbackAnimation.step = 0;        
}

Everything else should be commented out by putting two slashes ("//") in front of the line, like this:

//      if ( secondSweepbackAnimation.step >= secondsSweepbackAmounts.length )
//      {

Once you've made those changes, save the file back to disk.  Copy the file back into the "/Library/Widgets/World Clock.wdgt" directory and replace the original.  You may need to provide your root/admin password to do this.

Now you're ready to test it out.  Launch the Dashboard if it's not already up.  If the Dashboard was already up and World Clock is running, hold down the option key and move your mouse over it.  A close box should appear in the upper-left portion of the World Clock window.  Click this to close World Clock.  (You need to close World Clock so that it will pick up the changes we made to the script above.)

Now, launch World Clock again.  It should come up and begin working just fine, with the second-hand being displayed on-screen without the "wiggling" animation.  If it doesn't come up, you probably didn't make the proper changes in the WorldClock.js module.  Open it back up using the instructions above and make sure you commented out everything other than the lines that need to remain uncommented.

If you look in Activity Monitor, you should notice that the CPU usage of World Clock has dropped substantially after the changes.  If not, and you really want to keep that little wiggling second hand, all you need to do is reverse the changes you made earlier.  (If you followed my directions and made a second copy of the original "WorldClock.js" file, you can use it to replace the changed file to go back to the way it used to work.)


Related Blogs:

Related Links:

Last Updated ( Friday, 28 October 2005 )
< Previous   Next >

Main Menu
Home
Blog
Photos
Links
Search
Site Index
Feedback
Administrator
Featured Links
BlogInspiration
SpamToons
Shawn Prince's Blog
Jack Ludwig's Blog
Mike Cramer's Site
Fark
Slashdot
Woot!
Cigar Envy
John Kricfalusi's Blog
CigarBlog 101
Cigars 101 Forum
Sponsored Links


View Site Stats