|
|
Chromium Code Reviews|
Created:
4 years ago by Charlie Harrison Modified:
3 years, 11 months ago CC:
blink-reviews, blink-reviews-wtf_chromium.org, chromium-reviews, Mikhail Target Ref:
refs/pending/heads/master Project:
chromium Visibility:
Public. |
DescriptionCache contains only ascii in StringImpl
This patch adds a lazily calculated value in StringImpl for whether the
string contains only ascii characters. This avoids code that re-scans
the same string many times.
BUG=675493
Committed: https://crrev.com/36ecc9ec6ab699d9300f50fd4ca26030acad3e26
Cr-Commit-Position: refs/heads/master@{#441535}
Patch Set 1 #Patch Set 2 : cache contains only ascci #
Total comments: 1
Patch Set 3 : reviews #
Total comments: 22
Patch Set 4 : esprehn review #Patch Set 5 : DCHECK + static_Cast #
Messages
Total messages: 39 (27 generated)
The CQ bit was checked by csharrison@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: linux_android_rel_ng on master.tryserver.chromium.android (JOB_FAILED, https://build.chromium.org/p/tryserver.chromium.android/builders/linux_androi...)
The CQ bit was checked by csharrison@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: cast_shell_linux on master.tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/cast_shell_linu...)
The CQ bit was checked by csharrison@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: android_n5x_swarming_rel on master.tryserver.chromium.android (JOB_FAILED, https://build.chromium.org/p/tryserver.chromium.android/builders/android_n5x_...)
Description was changed from ========== Cache contains only ascii in StringImpl This patch adds a lazily calculated value in StringImpl for whether the string contains only ascii characters. This avoids code that re-scans the same string many times. BUG= ========== to ========== Cache contains only ascii in StringImpl This patch adds a lazily calculated value in StringImpl for whether the string contains only ascii characters. This avoids code that re-scans the same string many times. BUG=675493 ==========
csharrison@chromium.org changed reviewers: + esprehn@chromium.org, kinuko@chromium.org
esprehn, kinuko: here's the patch to cache containsOnlyASCII at StringImpl layer. There's some funkiness with type coercion from bool <-> enum, let me know if that bothers you and I can fix it up. I mainly did that to avoid conditionals/ternaries/switches. Also, there are a number of places where we might know this value ahead of time (i.e. substring, StringView::toString). I'll follow up in another CL, as I haven't found the best way to shape the API around that.
https://codereview.chromium.org/2585063002/diff/20001/third_party/WebKit/Sour... File third_party/WebKit/Source/wtf/text/StringImpl.h (right): https://codereview.chromium.org/2585063002/diff/20001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:554: : charactersAreAllASCII(characters16(), length())); I'd defer the judgement to esprehn (so you might want to hold off) but I'm not a big fan of this enum <-> boolean conversions (assuming we wouldn't get any perf benefit after optimization runs). Would clearly writing down the switches or ternaries make the code that bigger?
Since you're using two bits anyway you can use one bit for m_needsAsciiCheck and another for m_containsOnlyAscii with the first defaulted to true and the second to false.
On 2016/12/26 19:33:56, esprehn wrote: > Since you're using two bits anyway you can use one bit for m_needsAsciiCheck and > another for m_containsOnlyAscii with the first defaulted to true and the second > to false. After thinking about it for a bit, I have decided to go this route. PTAL?
https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... File third_party/WebKit/Source/wtf/text/StringImpl.h (right): https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:137: m_containsOnlyASCII(false), true https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:138: m_needsASCIICheck(true), false https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:155: m_containsOnlyASCII(false), m_containsOnlyASCII(true), the string is empty https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:156: m_needsASCIICheck(true), false https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:170: m_containsOnlyASCII(false), (!length) https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:171: m_needsASCIICheck(true), (length) https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:183: m_containsOnlyASCII(false), (!length) https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:184: m_needsASCIICheck(true), (length) https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:198: m_needsASCIICheck(true), ditto https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:548: !length() || Strings are immutable, so you don't need the length check here, you can do it in the constructor. https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:550: : charactersAreAllASCII(characters16(), length())); This is inlining a lot of code which I know the old code did, but instead I think you want to put the slow path in a separate out of line method, and only ALWAYS_INLINE the fast path. That'll actually be faster since it makes the functions smaller. ALWAYS_INLINE bool StringImpl::containsOnlyASCII() const { if (m_needsASCIICheck) updateContainsOnlyASCII(); return m_containsOnlyASCII; } and updateContainsOnlyASCII is in the .cpp file out of line.
The CQ bit was checked by csharrison@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
Thanks! https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... File third_party/WebKit/Source/wtf/text/StringImpl.h (right): https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:137: m_containsOnlyASCII(false), On 2017/01/04 20:30:37, esprehn wrote: > true Done. https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:138: m_needsASCIICheck(true), On 2017/01/04 20:30:37, esprehn wrote: > false Done. https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:155: m_containsOnlyASCII(false), On 2017/01/04 20:30:37, esprehn wrote: > m_containsOnlyASCII(true), the string is empty Done. https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:156: m_needsASCIICheck(true), On 2017/01/04 20:30:37, esprehn wrote: > false Done. https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:170: m_containsOnlyASCII(false), On 2017/01/04 20:30:37, esprehn wrote: > (!length) Done. https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:171: m_needsASCIICheck(true), On 2017/01/04 20:30:37, esprehn wrote: > (length) Done. https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:183: m_containsOnlyASCII(false), On 2017/01/04 20:30:37, esprehn wrote: > (!length) Done. https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:184: m_needsASCIICheck(true), On 2017/01/04 20:30:37, esprehn wrote: > (length) Done. https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:198: m_needsASCIICheck(true), On 2017/01/04 20:30:37, esprehn wrote: > ditto Done. https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:548: !length() || On 2017/01/04 20:30:37, esprehn wrote: > Strings are immutable, so you don't need the length check here, you can do it in > the constructor. Done. https://codereview.chromium.org/2585063002/diff/40001/third_party/WebKit/Sour... third_party/WebKit/Source/wtf/text/StringImpl.h:550: : charactersAreAllASCII(characters16(), length())); On 2017/01/04 20:30:37, esprehn wrote: > This is inlining a lot of code which I know the old code did, but instead I > think you want to put the slow path in a separate out of line method, and only > ALWAYS_INLINE the fast path. That'll actually be faster since it makes the > functions smaller. > > ALWAYS_INLINE bool StringImpl::containsOnlyASCII() const { > if (m_needsASCIICheck) > updateContainsOnlyASCII(); > return m_containsOnlyASCII; > } > > and updateContainsOnlyASCII is in the .cpp file out of line. SGTM. Done.
lgtm, I think you might want to add an if (!length) return true; check to the top of charactersAreAllASCII too for safety reasons, looking at that function I'm not sure it anticipates an empty string.
On 2017/01/04 at 20:57:50, esprehn wrote: > lgtm, I think you might want to add an if (!length) return true; check to the top of charactersAreAllASCII too for safety reasons, looking at that function I'm not sure it anticipates an empty string. .... or a DCHECK_GT(length, 0) since we handle the length checks in the constructor now.
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: cast_shell_android on master.tryserver.chromium.android (JOB_FAILED, https://build.chromium.org/p/tryserver.chromium.android/builders/cast_shell_a...)
The CQ bit was checked by csharrison@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
Added the DCHECK. I also had to static_cast<bool>(length) to initialize m_needsASCIICheck, as m_needsASCIICheck(unsigned) does not do bool coercion.
The CQ bit was checked by csharrison@chromium.org
The CQ bit was unchecked by csharrison@chromium.org
The CQ bit was checked by csharrison@chromium.org
The patchset sent to the CQ was uploaded after l-g-t-m from esprehn@chromium.org Link to the patchset: https://codereview.chromium.org/2585063002/#ps80001 (title: "DCHECK + static_Cast")
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
CQ is committing da patch.
Bot data: {"patchset_id": 80001, "attempt_start_ts": 1483566420429600,
"parent_rev": "05b3b665ced9e67a0ca5a6f17b5d8c5b77608aaa", "commit_rev":
"1ceea5ff18c4a5cc983215cc77c507707fc6985b"}
Message was sent while issue was closed.
Description was changed from ========== Cache contains only ascii in StringImpl This patch adds a lazily calculated value in StringImpl for whether the string contains only ascii characters. This avoids code that re-scans the same string many times. BUG=675493 ========== to ========== Cache contains only ascii in StringImpl This patch adds a lazily calculated value in StringImpl for whether the string contains only ascii characters. This avoids code that re-scans the same string many times. BUG=675493 Review-Url: https://codereview.chromium.org/2585063002 ==========
Message was sent while issue was closed.
Committed patchset #5 (id:80001)
Message was sent while issue was closed.
Description was changed from ========== Cache contains only ascii in StringImpl This patch adds a lazily calculated value in StringImpl for whether the string contains only ascii characters. This avoids code that re-scans the same string many times. BUG=675493 Review-Url: https://codereview.chromium.org/2585063002 ========== to ========== Cache contains only ascii in StringImpl This patch adds a lazily calculated value in StringImpl for whether the string contains only ascii characters. This avoids code that re-scans the same string many times. BUG=675493 Committed: https://crrev.com/36ecc9ec6ab699d9300f50fd4ca26030acad3e26 Cr-Commit-Position: refs/heads/master@{#441535} ==========
Message was sent while issue was closed.
Patchset 5 (id:??) landed as https://crrev.com/36ecc9ec6ab699d9300f50fd4ca26030acad3e26 Cr-Commit-Position: refs/heads/master@{#441535} |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
