Speeding up i18n
Matthias Kretz
kretz at kde.org
Tue Feb 3 09:51:01 GMT 2009
On Tuesday 03 February 2009 09:35:46 Olivier Goffart wrote:
> Le mardi 3 février 2009, John Tapsell a écrit :
> > Hi all,
> >
> > Has anyone looked into speeding up i18n calls by generating the
> > string hash at compile time rather than at runtime. Presumably it
> > could be done by a little bit of template magic in the i18n call.
> >
> > It would be interesting to investigate its effect on compile times
> > and application load times.
>
> I already tried to do operations on strings at compile time but without
> success.
> Using some template, and good optimisation flag, the compiler can optimize
> the hash computation of small strings, but once the string has a reasonable
> size, its not optimized.
>
> My objective was to keep strings simple to type., ie. STR("Some String")
> and not
> STR<'S', STR<'o', STR<'m', STR<'e' STR<' ', STR<'S', STR<'t', STR<'r',
> STR<'i', STR<'n', STR<'g'> > > > > > > > > > > >
AFAICS strings are immune to template and macro magic. The problem is that a
string in C/C++ always needs to point to memory where the string is. And
constant expressions refuse to work with anything that's a pointer.
The only reliable solution I can think of is to have the hashes computed by
something other than the compiler.
John, did you profile whether precomputing the hashes might actually do a
speedup?
Also keep in mind that modern computers often favor computation over memory
access by such a big factor that lookup-tables and other tricks that were very
useful some time ago can actually slow things down today.
So I recommend to not look into a solution until we have some idea of whether
the investment is worth the trouble.
--
________________________________________________________
Matthias Kretz (Germany) <><
http://Vir.homelinux.org/
More information about the kde-core-devel
mailing list