Go to file
Marc Mutz 0e7100d8c0 QTimeZone: optimize QTimeZonePrivate::isValidId()
This function is used in the named timezone ctor and was using QByteArray::split(),
followed by size checks and a linear scan for invalid chars per section. The use of
split() resulted in a lot of memory allocations and, unsurprisingly, bad performance.

The new code just performs one linear scan through the byte array, calculating
section sizes on the fly.

Benchmark results (with the test data in tst_QTimeZone::isValidId_data()) show
typical speedups of ~10x for valid IDs:

   RESULT : tst_QTimeZone::isValidId_bench():"minimal middle":
  -     0.00036 msecs per iteration (total: 95, iterations: 262144)
  +     0.000035 msecs per iteration (total: 74, iterations: 2097152)

Even in the sweet-spot case of the old code---a space character anywhere in the
string, checked for before the split---the new code is anywhere between slightly
faster and not much slower:

   RESULT : tst_QTimeZone::isValidId_bench():"invalid char ' ' front":
  -     0.000011 msecs per iteration (total: 94, iterations: 8388608)
  +     0.000010 msecs per iteration (total: 86, iterations: 8388608)
   RESULT : tst_QTimeZone::isValidId_bench():"invalid char ' ' middle":
  -     0.000014 msecs per iteration (total: 62, iterations: 4194304)
  +     0.000016 msecs per iteration (total: 69, iterations: 4194304)
   RESULT : tst_QTimeZone::isValidId_bench():"invalid char ' ' back":
  -     0.000018 msecs per iteration (total: 79, iterations: 4194304)
  +     0.000023 msecs per iteration (total: 98, iterations: 4194304)

This is not surprising, as the space character was singled out for a fast-exit
check before. For any other invalid character, the new version is anywhere from
15x to 35x faster:

   RESULT : tst_QTimeZone::isValidId_bench():"invalid char ? front":
  -     0.00034 msecs per iteration (total: 91, iterations: 262144)
  +     0.000010 msecs per iteration (total: 87, iterations: 8388608)
   RESULT : tst_QTimeZone::isValidId_bench():"invalid char ? middle":
  -     0.00036 msecs per iteration (total: 96, iterations: 262144)
  +     0.000016 msecs per iteration (total: 68, iterations: 4194304)
   RESULT : tst_QTimeZone::isValidId_bench():"invalid char ? back":
  -     0.00035 msecs per iteration (total: 94, iterations: 262144)
  +     0.000021 msecs per iteration (total: 92, iterations: 4194304)

If there was a deeper reason to single out the space character, that fast-exit
path can easily be restored.

This function is often used in conjunction with availableTimeZoneIds(), which
currently vastly dominates the runtime of the function calling both, but I'll
add another optimization for the common use-case of just checking for a time-zone's
existence in a subsequent commit.

Change-Id: Ife1d096fcd39464083ea464c23e49ad98fabf345
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2014-07-31 21:05:20 +02:00
bin syncqt: Fix regexp capturing class names of partial specialisation 2014-07-08 16:12:44 +02:00
config.tests Add the detection of the compiler macros for more AVX512 features 2014-07-31 00:52:37 +02:00
dist Tidy up and expand QSharedPointer documentation. 2014-07-03 10:57:40 +02:00
doc Doc: Add Qt 5 URL in qtbase/doc/global 2014-07-04 12:05:01 +02:00
examples Make hellogl work properly regardless of vsync 2014-07-31 18:35:39 +02:00
lib Initial import from the monolithic Qt. 2011-04-27 12:05:43 +02:00
mkspecs Fix iOS simulator build after 1f0823c (Rewrite simd.prf to share more code) 2014-07-30 19:37:52 +02:00
qmake Xcode: Reference files by absolute path, and name them by basename only 2014-07-31 18:37:05 +02:00
src QTimeZone: optimize QTimeZonePrivate::isValidId() 2014-07-31 21:05:20 +02:00
tests tst_QTimeZone: test QTimeZonePrivate::isValidId() 2014-07-31 21:05:07 +02:00
tools Merge remote-tracking branch 'origin/5.3' into dev 2014-07-29 12:56:06 +02:00
util Mark all QChar static functions as [[gnu::const]] 2014-07-07 03:51:43 +02:00
.gitattributes Update the git-archive export options 2012-09-07 15:39:31 +02:00
.gitignore Add .dylib and .d to .gitignore 2014-03-29 00:40:46 +01:00
.qmake.conf Enable -Werror for all of qtbase 2013-09-04 01:50:10 +02:00
.tag Update the git-archive export options 2012-09-07 15:39:31 +02:00
configure Merge remote-tracking branch 'origin/5.3' into dev 2014-07-29 12:56:06 +02:00
configure.bat get rid of syncqt wrapper scripts 2013-05-13 21:54:48 +02:00
header.BSD Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
header.FDL Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
header.LGPL Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
header.LGPL-ONLY Update copyright year in Digia's license headers 2013-01-18 09:07:35 +01:00
INSTALL Doc: Update links in INSTALL file 2014-01-16 20:37:25 +01:00
LGPL_EXCEPTION.txt Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
LICENSE.FDL Initial import from the monolithic Qt. 2011-04-27 12:05:43 +02:00
LICENSE.GPL Add the LICENSE.GPL file to the module referenced from license headers 2012-05-20 22:41:08 +02:00
LICENSE.LGPL Update copyright year in LICENSE.LGPL 2014-03-31 12:36:33 +02:00
LICENSE.PREVIEW.COMMERCIAL Update LICENSE.PREVIEW.COMMERCIAL license 2013-06-03 20:04:26 +02:00
qtbase.pro untangle use of system vs. shell path(-list) semantics 2014-04-30 16:56:54 +02:00
sync.profile Merge remote-tracking branch 'origin/5.3' into dev 2014-07-22 20:21:19 +02:00