CMake project import - CPU usage due to QRegExp performance bug
Manuel Massing
m.massing at warped-space.de
Sun Feb 27 19:25:19 UTC 2011
Hi,
while investigating cmake project parsing, I've found a huge performance
problem in the QRegExp parser. Basically the matching of a single regular
expression pegs my CPU at 100% for nearly 2 minutes (i5 at 2.6 GHZ),
This single regular expression accounts for nearly all of the project import
time!
The problem is due to a regular expression in FindZLIB.cmake, which is
part of the cmake distribution, and included by many cmake projects/modules
(/usr/share/cmake-2.8/Modules/FindZLIB.cmake). The culprit:
STRING(REGEX REPLACE ".*#define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.
([0-9]+)\".*" "\\1.\\2.\\3" ZLIB_VERSION_STRING "${ZLIB_H}")
Here, ZLIB_H holds the contents of the zlib include file
(/usr/include/zlib.h).
This expression is handled in "int CMakeProjectVisitor::visit(const StringAst
*sast)", cmakeprojectvisitor:1772.
In case QRegExp can match the regular expression, the query executes quickly.
However, if the regular expression does not match (which is the case for zlib
version 1.2.3.4, which defines the version as "#define ZLIB_VERSION
"1.2.3.4"), QRegExp gets caught in a low-performance search. This is probably
a bug or bad heurisitc in QRegExp.
I'll probably report this issue via the qt bug tracker, but maybe someone has
an idea on how to work around this issue, or what might cause QRegExp to
break down so badly?
Anyway, also meant as a heads up to everyone who was wondering wtf the cmake
parser might be doing with all the cpu time :-)
bye,
Manuel
Simple test case attached - fails for any file which does not match the
regexp, specifically zlib 1.2.3.4)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20110227/e60c8fb8/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qregexp-performance.cpp
Type: text/x-c++src
Size: 699 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20110227/e60c8fb8/attachment.cpp>
More information about the KDevelop-devel
mailing list