Caching local time zone

johnflux at johnflux at
Thu Sep 21 14:56:31 BST 2006

I ran into a very similiar problem with formatNumber.  I use this
hundreds of times a second in ksysguard at startup, and the problem is
that it has to check the locale you are in to know how to format the
number correctly.  To check the locale it seems to do a bunch of IO.
I will look into it again at akademy as I cant quite remember the
details now

On 21/09/06, Lubos Lunak <l.lunak at> wrote:
> On Thursday 21 September 2006 11:04, David Jarvie wrote:
> > Using KDateTime for date/times in the local time zone can potentially
> > result in very frequent calls to KSystemTimeZones::local() which fetches
> > and returns the current local system time zone. Depending on the system,
> > that function may open and read files, and compare their contents. Even if
> > the files are still cached (as would usually be the case on a UNIX system
> > when the function calls are made in quick succession), the overhead in
> file
> > system function calls makes me feel uneasy when the function could be
> > called many times a second if arrays of date/time values are being
> > converted to or from the local time zone.
>  Ah, so that's why the class does such awful amount of unnecessary I/O? Note
> that this does not only affect runtime but also KDE startup (since the I/O
> cannot be cached at that time, kernel has pretty bad performance when it
> comes to many small files and of course everybody has the clock applet).
> Just
> strace -f startkde to see.
>  I'd first suggest rethinking the design. Say, a kded module (with the right
> kded startup phase, see kdebase/ksmserver/README) that does whatever initial
> checks needed, saves the current timezone to some config file and KTimeZone
> uses only that. Next startup the module only checks if there have been any
> changes and does nothing if not. Checking for changes while KDE is running
> can be done using a file watch.
> > Plainly, the system time zone is not going to change frequently, so I
> think
> > that it would be better to cache it and only reread it periodically. I
> > propose to set a timer to refresh it once a minute. Any
> > comments/objections?
> >
> > Note that this caching applies to the time *zone* (e.g. "Europe/Paris").
> It
> > has no impact on the handling of daylight saving time shifts which will
> > still be handled without any time lag.
> --
> Lubos Lunak
> KDE developer
> --------------------------------------------------------------
> SUSE LINUX, s.r.o.   e-mail: l.lunak at , l.lunak at
> Lihovarska 1060/12   tel: +420 284 028 972
> 190 00 Prague 9      fax: +420 284 028 951
> Czech Republic       http//

More information about the kde-core-devel mailing list