Am Donnerstag, 31. Oktober 2013, 17:52:28 schrieb Jiergir Ogoerg:
> Great, of course you're a much better/smarter programmer than me,
> but how much time of the whole parsing and loading
> (which is done line by line which is slow) does fromUtf8()
> take? If it's only like 10-20% then even if it's optimized to work 10 times
> faster in the end it's a much smaller improvement compared to
> binary loading which almost doesn't do any parsing at all, just copying
> from disk onto ready memory.
Hey,
I was curious about performance bottlenecks here, too, this morning. So I had
a quick look.
Results:
Running the attached program (main.cpp) compiled with 'g++ -g -O2 ...' through
callgrind yielded the following results for me:
Just showing the significant measurements:
* ~50% time (incl.) spent in xkb_keysym_from_name
* ~21% time (incl.) spent in QString::fromUtf8_helper
So it seems there's indeed potential that optimizing QString::fromUtf8 would
help. Not sure if there's any benefit in looking into xkb_keysym_from_name
from xkb-common, which seems to be another bottleneck.
> If the total parsing time after your optimizations
> is still like 2x+ times slower than loading the binary cache then imo
> your optimizations should be incorporated anyway for the
> (rare) cases when there's no (binary) cache yet or when it must be updated.
>
> The type of code (in a loop) I mentioned which features lots of other
> decoding/operations
> besides fromUtf8():
>
> (snip)
While having a quick look at the code in qtablegenerator.cpp I found a minor
performance bottleneck, patch attached.
With this patch, some iterations of the for-loop inside
TableGenerator::parseKeySequence are saved. Given that the amount of keys
inside the compose text file is significant smaller than
QT_KEYSEQUENCE_MAX_LEN (== 6) in average.
Callgrind results (Instruction fetches):
* Without patch: ~34,350k
* With patch: ~34,200k
Minor improvement, yes.
If the patch makes sense (i.e. if it is correct) I can put it on Gerrit.
Greets
--
Kevin Funk
#include "qtablegenerator.h"
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
QFile file("/usr/share/X11/locale/en_US.UTF-8/Compose");
bool rc = file.open(QIODevice::ReadOnly);
Q_ASSERT(rc);
clock_t begin = clock();
TableGenerator gen;
gen.parseComposeFile(&file);
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
cout << elapsed_secs << endl;
}
diff --git a/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp b/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp
index 4cfc2a6..38cf267 100644
--- a/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp
+++ b/src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp
@@ -350,7 +350,7 @@ void TableGenerator::parseKeySequence(char *line)
if (!keysEnd)
return;
- QComposeTableElement elem;
+ QComposeTableElement elem = {};
// find the composed value - strings may be direct text encoded in the locale
// for which the compose file is to be used, or an escaped octal or hexadecimal
// character code. Octal codes are specified as "\123" and hexadecimal codes as "\0x123a".
@@ -409,7 +409,7 @@ void TableGenerator::parseKeySequence(char *line)
qWarning() << QString("Qt Warning - invalid keysym: %1").arg(sym);
}
} else {
- elem.keys[i] = 0;
+ break;
}
}
m_composeTable.append(elem);
_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development