Changeset 209858 in webkit
- Timestamp:
- Dec 15, 2016 2:28:55 AM (7 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r209813 r209858 1 2016-12-15 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 [JSC] Optimize Kraken stringify 4 https://bugs.webkit.org/show_bug.cgi?id=165857 5 6 Reviewed by Darin Adler. 7 8 Kraken json-stringify-tinderbox performance heavily relies on StringBuilder::appendQuotedJSONString. 9 According to the result produced by Linux `perf`, it occupies 28% of execution time. 10 11 We tighten the hottest loop in the above function. We create the super fast path for non escaping case. 12 And add " and \ cases (since including " in the string is common). Then we fallback to the slow case. 13 14 It improves the performance 5.5% in Kraken json-stringify-tinderbox in MBP. 15 16 Performance result in my MBP (dandelion). 17 18 Collected 100 samples per benchmark/VM, with 100 VM invocations per benchmark. Emitted a call to gc() 19 between sample measurements. Used 1 benchmark iteration per VM invocation for warm-up. Used the 20 jsc-specific preciseTime() function to get microsecond-level timing. Reporting benchmark execution times 21 with 95% confidence intervals in milliseconds. 22 23 baseline patched 24 25 json-stringify-tinderbox 29.243+-0.241 ^ 27.701+-0.235 ^ definitely 1.0557x faster 26 27 <arithmetic> 29.243+-0.241 ^ 27.701+-0.235 ^ definitely 1.0557x faster 28 29 Performance result in my Linux laptop (hanayamata). 30 31 Collected 100 samples per benchmark/VM, with 100 VM invocations per benchmark. Emitted a call to gc() 32 between sample measurements. Used 1 benchmark iteration per VM invocation for warm-up. Used the 33 jsc-specific preciseTime() function to get microsecond-level timing. Reporting benchmark execution times 34 with 95% confidence intervals in milliseconds. 35 36 baseline patched 37 38 json-stringify-tinderbox 26.711+-0.475 ^ 25.255+-0.034 ^ definitely 1.0577x faster 39 40 <arithmetic> 26.711+-0.475 ^ 25.255+-0.034 ^ definitely 1.0577x faster 41 42 * wtf/text/StringBuilder.cpp: 43 (WTF::appendQuotedJSONStringInternalSlow): 44 (WTF::appendQuotedJSONStringInternal): 45 1 46 2016-12-14 Commit Queue <commit-queue@webkit.org> 2 47 -
trunk/Source/WTF/wtf/text/StringBuilder.cpp
r209399 r209858 387 387 388 388 template <typename OutputCharacterType, typename InputCharacterType> 389 static void appendQuotedJSONStringInternalSlow(OutputCharacterType*& output, const InputCharacterType character) 390 { 391 switch (character) { 392 case '\t': 393 *output++ = '\\'; 394 *output++ = 't'; 395 break; 396 case '\r': 397 *output++ = '\\'; 398 *output++ = 'r'; 399 break; 400 case '\n': 401 *output++ = '\\'; 402 *output++ = 'n'; 403 break; 404 case '\f': 405 *output++ = '\\'; 406 *output++ = 'f'; 407 break; 408 case '\b': 409 *output++ = '\\'; 410 *output++ = 'b'; 411 break; 412 default: 413 ASSERT(!(character & 0xFF00)); 414 *output++ = '\\'; 415 *output++ = 'u'; 416 *output++ = '0'; 417 *output++ = '0'; 418 *output++ = upperNibbleToLowercaseASCIIHexDigit(character); 419 *output++ = lowerNibbleToLowercaseASCIIHexDigit(character); 420 break; 421 } 422 } 423 424 template <typename OutputCharacterType, typename InputCharacterType> 389 425 static void appendQuotedJSONStringInternal(OutputCharacterType*& output, const InputCharacterType* input, unsigned length) 390 426 { 391 427 for (const InputCharacterType* end = input + length; input != end; ++input) { 392 if (LIKELY(*input > 0x1F)) { 393 if (*input == '"' || *input == '\\') 394 *output++ = '\\'; 395 *output++ = *input; 428 const InputCharacterType character = *input; 429 if (LIKELY(character != '"' && character != '\\' && character > 0x1F)) { 430 *output++ = character; 396 431 continue; 397 432 } 398 switch (*input) { 399 case '\t':433 434 if (character == '"' || character == '\\') { 400 435 *output++ = '\\'; 401 *output++ = 't'; 402 break; 403 case '\r': 404 *output++ = '\\'; 405 *output++ = 'r'; 406 break; 407 case '\n': 408 *output++ = '\\'; 409 *output++ = 'n'; 410 break; 411 case '\f': 412 *output++ = '\\'; 413 *output++ = 'f'; 414 break; 415 case '\b': 416 *output++ = '\\'; 417 *output++ = 'b'; 418 break; 419 default: 420 ASSERT((*input & 0xFF00) == 0); 421 *output++ = '\\'; 422 *output++ = 'u'; 423 *output++ = '0'; 424 *output++ = '0'; 425 *output++ = upperNibbleToLowercaseASCIIHexDigit(*input); 426 *output++ = lowerNibbleToLowercaseASCIIHexDigit(*input); 427 break; 428 } 436 *output++ = character; 437 continue; 438 } 439 440 appendQuotedJSONStringInternalSlow(output, character); 429 441 } 430 442 }
Note: See TracChangeset
for help on using the changeset viewer.