Closed
Bug 641725
Opened 14 years ago
Closed 2 months ago
using word-wise comparison to improve performance
Categories
(Core :: General, defect)
Core
General
Tracking
()
RESOLVED
WONTFIX
People
(Reporter: songlinhai, Unassigned)
Details
User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15
Build Identifier: firefox-4.0b11
There are many code fragments which compare two strings or one string with a
constant character in mozilla. These comparisons continue when two characters
are equal to each other, and stop when two characters are not equal. This byte-wise comparison process can be optimized by word-wise comparison.
According to my current knowledge, there are no compiler can do this optimization.
I did unit test for word-wise comparison and byte-wise comparison.
When the common length is smaller than 4 bytes, there is negligible performance
difference.
When the common length is larger than 4 bytes, word-wise comparison runs much faster.
For example, when common length is 10 bytes, word-wise comparison only takes about 3/4 the time the byte-wise comparison takes. And when
the common length is 20, word-wise comparison only takes about HALF
the time byte-wise comparison takes.
I list all byte-wise comparison as follows:
/firefox-4.0b11.source/netwerk/protocol/http/nsHttpNTLMAuth.cpp:382
while (challenge[len - 1] == '=')
// strip off any padding (see bug 230351)
while (challenge[len - 1] == '=')
len--;
=========================================================================
/firefox-4.0b11.source/netwerk/base/src/nsURLHelper.cpp:600
while (((p-1) >= str) && (*(p-1) == ' ')) {
// Remove trailing spaces if any
while (((p-1) >= str) && (*(p-1) == ' ')) {
writing = PR_TRUE;
p--;
}
============================================================================
/firefox-4.0b11.source/extensions/spellcheck/hunspell/src/hunspell.cpp:190
while ((nl > 0) && (*(q+nl-1)=='.')) {
*pabbrev = 0;
int nl = strlen((const char *)q);
while ((nl > 0) && (*(q+nl-1)=='.')) {
nl--;
(*pabbrev)++;
}
==============================================================================
/firefox-4.0b11.source/extensions/spellcheck/hunspell/src/hunspell.cpp:146
while ((nl > 0) && (*(q+nl-1)=='.')) {
while ((nl > 0) && (*(q+nl-1)=='.')) {
nl--;
(*pabbrev)++;
}
=============================================================================
/firefox-4.0b11.source/extensions/auth/nsHttpNegotiateAuth.cpp:260
while (challenge[len - 1] == '=')
// strip off any padding (see bug 230351)
while (challenge[len - 1] == '=')
len--;
===============================================================================
/firefox-4.0b11.source/security/manager/ssl/src/nsKeygenHandler.cpp:162
for (i = 0; params->prime.data[i] == 0; i++)
for (i = 0; params->prime.data[i] == 0; i++)
/* empty */;
=============================================================================
/firefox-4.0b11.source/db/sqlite3/src/sqlite3.c:105181
while( n>0 && z[n-1]==' ' ){ n--; }
=============================================================================
/firefox-4.0b11.source/db/sqlite3/src/sqlite3.c:18792
while( bufpt[-1]=='0' ) *(--bufpt) = 0;
=============================================================================
/firefox-4.0b11.source/db/sqlite3/src/sqlite3.c:98304
while( n>1 && zAff[n-1]==SQLITE_AFF_NONE ){
while( n>1 && zAff[n-1]==SQLITE_AFF_NONE ){
n--;
}
=============================================================================
/firefox-4.0b11.source/js/src/config/nsinstall.c:112
while (*path == '/' && path[1] == '/')
while (*path == '/' && path[1] == '/')
path++;
============================================================================
/firefox-4.0b11.source/js/src/config/nsinstall.c:114
for (cp = strrchr(path, '/'); cp && cp != path && *(cp - 1) == '/'; cp--);
============================================================================
/firefox-4.0b11.source/js/src/jsopcode.cpp:3090
while (ss->opcodes[pos] == JSOP_ENTERBLOCK) {
/*
* Now move pos downward over the block's local slots. Even an
* empty destructuring pattern has one (dummy) local.
*/
while (ss->opcodes[pos] == JSOP_ENTERBLOCK) {
if (pos == 0)
break;
--pos;
}
=============================================================================
/firefox-4.0b11.source/js/src/dtoa.c:2903
while(*--s == '0');
============================================================================
/firefox-4.0b11.source/js/src/dtoa.c:2959
while(*--s == '9')
while(*--s == '9')
if (s == s0) {
k++;
*s = '0';
break;
}
++*s++;
}
=============================================================================
/firefox-4.0b11.source/js/src/dtoa.c:3212
while(*--s == '9')
while(*--s == '9')
if (s == s0) {
k++;
*s++ = '1';
goto ret;
}
++*s++;
}
=============================================================================
/firefox-4.0b11.source/js/src/dtoa.c:3224
while(*--s == '0');
=============================================================================
/firefox-4.0b11.source/js/src/dtoa.c:1537
while(*++s == '0') ;
=============================================================================
/firefox-4.0b11.source/xpcom/io/nsWildCard.cpp:315
while(expr[++y] == '*'){}
==============================================================================
/firefox-4.0b11.source/nsprpub/pr/src/misc/prdtoa.c:3077
while(*--s == '0');
=============================================================================
/firefox-4.0b11.source/nsprpub/pr/src/misc/prdtoa.c:3133
while(*--s == '9')
while(*--s == '9')
if (s == s0) {
k++;
*s = '0';
break;
}
++*s++;
}
==============================================================================
/firefox-4.0b11.source/nsprpub/pr/src/misc/prdtoa.c:3384
while(*--s == '9')
while(*--s == '9')
if (s == s0) {
k++;
*s++ = '1';
goto ret;
}
++*s++;
}
============================================================================
/firefox-4.0b11.source/nsprpub/pr/src/misc/prdtoa.c:3396
while(*--s == '0');
============================================================================
/firefox-4.0b11.source/nsprpub/pr/src/misc/prdtoa.c:1685
while(*++s == '0') ;
=============================================================================
/firefox-4.0b11.source/nsprpub/config/nsinstall.c:136
while (*path == '/' && path[1] == '/')
while (*path == '/' && path[1] == '/')
path++;
==============================================================================
/firefox-4.0b11.source/nsprpub/config/nsinstall.c:138
for (cp = strrchr(path, '/'); cp && cp != path && cp[-1] == '/'; cp--)
for (cp = strrchr(path, '/'); cp && cp != path && cp[-1] == '/'; cp--)
;
===========================================================================
/firefox-4.0b11.source/config/nsinstall.c:112
while (*path == '/' && path[1] == '/')
while (*path == '/' && path[1] == '/')
path++;
============================================================================
/firefox-4.0b11.source/config/nsinstall.c:114
for (cp = strrchr(path, '/'); cp && cp != path && *(cp - 1) == '/'; cp--);
============================================================================
/firefox-4.0b11.source/security/nss/lib/util/quickder.c:829
while (temp.len > 1 && temp.data[0] == 0)
while (temp.len > 1 && temp.data[0] == 0)
{ /* leading 0 */
temp.data++;
temp.len--;
}
==========================================================================
/firefox-4.0b11.source/security/nss/lib/util/portreg.c:259
while(exp[++y] == '*'){}
=========================================================================
/firefox-4.0b11.source/security/nss/lib/util/secasn1d.c:1565
while (len > 1 && buf[0] == 0) { /* leading 0 */
while (len > 1 && buf[0] == 0) { /* leading 0 */
buf++;
len--;
}
============================================================================
/firefox-4.0b11.source/security/nss/lib/softoken/ecdecode.c:68
while ((tmp > 2) && (str[0] == '0') && (str[1] == '0')) {
/* skip leading 00's unless the hex string is "00" */
while ((tmp > 2) && (str[0] == '0') && (str[1] == '0')) {
str += 2;
tmp -= 2;
}
===========================================================================
/firefox-4.0b11.source/security/nss/cmd/certutil/keystuff.c:287
for (i = 0; params->prime.data[i] == 0; i++) {
for (i = 0; params->prime.data[i] == 0; i++) {
/* empty */;
}
Reproducible: Always
Steps to Reproduce:
1.code review
2.
3.
Updated•2 years ago
|
Severity: normal → S3
Comment 1•2 months ago
|
||
No activity for a while and probably fixed/not needed anymore. Closing.
Status: UNCONFIRMED → RESOLVED
Closed: 2 months ago
Resolution: --- → WONTFIX
You need to log in
before you can comment on or make changes to this bug.
Description
•