Closed
Bug 1386103
Opened 7 years ago
Closed 7 years ago
Specify nsAuto[C]String length via template parameter
Categories
(Core :: XPCOM, enhancement)
Tracking
()
RESOLVED
FIXED
mozilla57
Tracking | Status | |
---|---|---|
firefox57 | --- | fixed |
People
(Reporter: n.nethercote, Assigned: n.nethercote)
References
(Blocks 1 open bug)
Details
Attachments
(3 files)
(deleted),
patch
|
dbaron
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
erahm
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
kats
:
review+
|
Details | Diff | Splinter Review |
nsAuto[C]String contain 64 chars inline. This is usually fine, but occasionally we'd like to specify a different number of chars. We can do this with templates.
Assignee | ||
Comment 1•7 years ago
|
||
This patch parameterizes nsAuto[C]String, renames them as nsAuto[C]StringN, and
redefines nsAuto[C]String as typedefs for nsAuto[C]StringN<64>.
(The alternative would be to templatize nsAuto[C]String and use a default
parameter, but that would require writing "nsAuto[C]String<>" everywhere.)
Attachment #8892379 -
Flags: review?(dbaron)
Assignee | ||
Updated•7 years ago
|
Assignee: nobody → n.nethercote
Status: NEW → ASSIGNED
Assignee | ||
Comment 2•7 years ago
|
||
In all of these cases the fixed buffer has the same lifetime as the string
object, so we can use nsAuto[C]String for simplicity.
For the 128-length ones in dom/xul/ I just switched to the default of 64 for
simplicity, because the choice of 128 didn't seem that important.
Finally, the patch also changes LoggingIdString to use
nsAutoCStringN<NSID_LENGTH>, similar to NullPrincipalURI.
Attachment #8892382 -
Flags: review?(dbaron)
Comment 3•7 years ago
|
||
I'm wondering if there are better naming options here. I'm not crazy about the "N" name. (Would reusing the FixedString name be a good idea or not?)
Assignee | ||
Comment 4•7 years ago
|
||
I deliberately left the default 64-char cases as nsAuto[C]String, to avoid massive amounts of churn.
It makes sense for the class name to be something similar to nsAuto[C]String. erahm was using nsBaseAuto[C]String at one point.
I chose nsAuto[C]StringN because it mirrors nsAuto[C]String<N>. TBH I don't think it matters all that much because the default 64-char case is so much more common.
Comment 5•7 years ago
|
||
I would like to encourage people to use different sizes a bit more than today, though.
Comment 6•7 years ago
|
||
(In reply to David Baron :dbaron: ⌚️UTC+2 from comment #5)
> I would like to encourage people to use different sizes a bit more than
> today, though.
Do we think we have a good handle on how long strings typically are at given callsites, though? For nsAutoTArray, we can usually say "1" or "4" or whichever; I don't know that we have that same intuition around strings. (Though std::string implementations seem to have converged on something much less than 64, so maybe we should bump ours down anyway!)
Assignee | ||
Comment 7•7 years ago
|
||
> Do we think we have a good handle on how long strings typically are at given
> callsites, though?
I don't know. They're mostly on the stack, in which case it maybe doesn't matter that much, so long as functions aren't recursive? But changing the default size is beyond the scope of this bug.
Anyway, the main sticking point seems to be the class name. The names I considered:
- nsBaseAuto[C]String
- nsAutoN[C]String
- nsAuto[C]StringN
I thought the last one was the best, so I used it in the patch. I'm happy to hear other suggestions.
Comment 8•7 years ago
|
||
(In reply to David Baron :dbaron: ⌚️UTC+2 from comment #3)
> I'm wondering if there are better naming options here. I'm not crazy about
> the "N" name. (Would reusing the FixedString name be a good idea or not?)
FixedString sounds like something that can't change size, nsAutoString definitely can.
(In reply to Nicholas Nethercote [:njn] from comment #7)
> Anyway, the main sticking point seems to be the class name. The names I
> considered:
>
> - nsBaseAuto[C]String
>
> - nsAutoN[C]String
>
> - nsAuto[C]StringN
>
> I thought the last one was the best, so I used it in the patch. I'm happy to
> hear other suggestions.
nsAutoN[C]String aligns well with nsAutoTArray. I'm not sure if that's a compelling argument though.
Comment 9•7 years ago
|
||
(In reply to Eric Rahm [:erahm] (please no mozreview requests) from comment #8)
> nsAutoN[C]String aligns well with nsAutoTArray. I'm not sure if that's a
> compelling argument though.
It has the disadvantage of having a bunch of capital letters in a row that could be hard to parse, especially with nsAutoNCString.
I guess I'm inclined to just go with the names in njn's current patch.
Updated•7 years ago
|
Attachment #8892379 -
Flags: review?(dbaron) → review+
Assignee | ||
Comment 10•7 years ago
|
||
Comment on attachment 8892382 [details] [diff] [review]
(part 2) - Convert nsFixed[C]String uses to nsAuto[C]String
Review of attachment 8892382 [details] [diff] [review]:
-----------------------------------------------------------------
Redirecting review request.
Attachment #8892382 -
Flags: review?(dbaron) → review?(erahm)
Comment 11•7 years ago
|
||
Comment on attachment 8892382 [details] [diff] [review]
(part 2) - Convert nsFixed[C]String uses to nsAuto[C]String
Review of attachment 8892382 [details] [diff] [review]:
-----------------------------------------------------------------
r=me with confirmation that switching to 64 is fine.
::: caps/NullPrincipalURI.cpp
@@ +39,5 @@
> NS_ENSURE_SUCCESS(rv, rv);
>
> + mPath.SetLength(NSID_LENGTH - 1); // -1 because NSID_LENGTH counts the '\0'
> + id.ToProvidedString(
> + *reinterpret_cast<char(*)[NSID_LENGTH]>(mPath.BeginWriting()));
This is rough, I wonder if we could add a `GetFixedBuffer` to nsAutoCStringN in a follow up or `nsID::ToProvidedString(nsAutoCStringN<NSID_LENGTH>&)`.
::: dom/xul/templates/nsXULContentBuilder.cpp
@@ +599,5 @@
> // actual value of the 'rdf:resource' attribute for the
> // given node.
> // SynchronizeUsingTemplate contains code used to update textnodes,
> // so make sure to modify both when changing this
> + nsAutoString attrValue;
This is shrinking from 128 -> 64, I know you thought it was arbitrary but is it possible to dump the string sizes on startup and confirm?
Attachment #8892382 -
Flags: review?(erahm) → review+
Assignee | ||
Comment 12•7 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/3f9ec011c9bd5da36b51cb09a81151db70135068
Bug 1386103 (part 1) - Specify nsAuto[C]String storage size via template parameter. r=dbaron.
https://hg.mozilla.org/integration/mozilla-inbound/rev/eec506d87d03103778da654b7755b93a8fad7ae9
Bug 1386103 (part 2) - Convert nsFixed[C]String uses to nsAuto[C]String. r=erahm.
Comment 13•7 years ago
|
||
Backed out in https://hg.mozilla.org/integration/mozilla-inbound/rev/81fbe7dc05a6 for the incomprehensible muddle of https://treeherder.mozilla.org/logviewer.html#?job_id=121873730&repo=mozilla-inbound on Android x86.
Updated•7 years ago
|
Flags: needinfo?(n.nethercote)
Assignee | ||
Comment 14•7 years ago
|
||
> This is shrinking from 128 -> 64, I know you thought it was arbitrary but is
> it possible to dump the string sizes on startup and confirm?
I started and opened several sites and didn't hit these code paths.
Assignee | ||
Comment 15•7 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/07241c0f20c10733574d4b71b67d2aa2d643d581
Bug 1386103 (part 1, attempt 2) - Specify nsAuto[C]String storage size via template parameter. r=dbaron.
https://hg.mozilla.org/integration/mozilla-inbound/rev/9031387c7ef1fe1db4b68495d1527b56e464c817
Bug 1386103 (part 2, attempt 2) - Convert nsFixed[C]String uses to nsAuto[C]String. r=erahm.
Comment 16•7 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/07241c0f20c1
https://hg.mozilla.org/mozilla-central/rev/9031387c7ef1
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
status-firefox57:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla57
Comment 17•7 years ago
|
||
Hmm, the changesets you landed are empty :-(
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Assignee | ||
Comment 18•7 years ago
|
||
(In reply to Jorg K (GMT+2) from comment #17)
> Hmm, the changesets you landed are empty :-(
They are! Thanks for pointing this out :)
Flags: needinfo?(n.nethercote)
Assignee | ||
Comment 19•7 years ago
|
||
The Android x86 opt problem is in part 1. It didn't show up when I did my original try push, but something happened between then and my landing attempt.
https://treeherder.mozilla.org/#/jobs?repo=try&revision=3f6d5b14c51c52a184a9010c716b601e36c9974 is a try job that shows the build failure. There are two very similar errors, both of which are multi-KiB C++ template monstrosities involving NDK headers, NDK types and mozilla::ContainerState::SetupMaskLayerForCSSMask.
The Mozilla code in question looks like this:
> RefPtr<ImageLayer> maskLayer =
> CreateOrRecycleMaskImageLayerFor(MaskLayerKey(aLayer, Nothing()),
> [](Layer* aMaskLayer)
> {
> aMaskLayer->SetUserData(&gCSSMaskLayerUserData,
> new CSSMaskLayerUserData());
> }
> );
I see no connection between any of this and my nsAuto[C]String changes :(
Assignee | ||
Comment 20•7 years ago
|
||
dvander: this bug is about nsAutoString. Somehow the changes in part 1 are
causing an indecipherable and seemingly unrelated compile error in
FrameLayerBuilder.cpp on Android 4.2 x86 opt. (See comment 19 for more
details.)
It smells like a compiler bug. Using function pointers instead of lambdas is
enough to quell it, so that's what this patch does.
Attachment #8895678 -
Flags: review?(dvander)
Assignee | ||
Comment 21•7 years ago
|
||
dvander: 1 week review ping!
Comment 22•7 years ago
|
||
(fyi: dvander's on PTO for another week)
Assignee | ||
Comment 23•7 years ago
|
||
Comment on attachment 8895678 [details] [diff] [review]
(part 0) - Don't pass lambdas to CreateOrRecycledMaskImageLayerFor
Review of attachment 8895678 [details] [diff] [review]:
-----------------------------------------------------------------
kats: thank you for the info. Would you mind taking over? It's a very small patch :)
Attachment #8895678 -
Flags: review?(dvander) → review?(bugmail)
Updated•7 years ago
|
Attachment #8895678 -
Flags: review?(bugmail) → review+
Comment 24•7 years ago
|
||
/cc Botond as well as he might be interested in the compiler bug and aforementioned C++ template monstrosities.
Assignee | ||
Comment 25•7 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/b0bdc6c0e7ef5fdb86e8fd3fb276b2c9cab364ad
Bug 1386103 (part 0) - Don't pass lambdas to CreateOrRecycledMaskImageLayerFor. r=kats.
https://hg.mozilla.org/integration/mozilla-inbound/rev/14de940bb317a497f50f6e80a1b5439fe9d049a6
Bug 1386103 (part 1, attempt 3) - Specify nsAuto[C]String storage size via template parameter. r=dbaron.
https://hg.mozilla.org/integration/mozilla-inbound/rev/a5f0bad7a33adbe4a0802a65977069dec6a002d5
Bug 1386103 (part 2, attempt 3) - Convert nsFixed[C]String uses to nsAuto[C]String. r=erahm.
Comment 26•7 years ago
|
||
(In reply to Kartikaya Gupta (email:kats@mozilla.com) from comment #24)
> /cc Botond as well as he might be interested in the compiler bug and
> aforementioned C++ template monstrosities.
We've seen errors exactly like this in bug 1367798. There, too, they were triggered by unrelated changes to the codebase.
I provided some analysis of the errors in bug 1367798 comment 7 and bug 1367798 comment 9. My conclusion was that, unlikely as it seems, we appear to be running into some sort of undefined behaviour in the compiler. Having this issue crop up in yet another unrelated scenario strengthens that hypothesis.
So, Nick, I think you're right about this being a compiler bug, and your workaround is appropriate.
Assignee | ||
Comment 27•7 years ago
|
||
Thank you for the extra info, Botond.
Comment 28•7 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/b0bdc6c0e7ef
https://hg.mozilla.org/mozilla-central/rev/14de940bb317
https://hg.mozilla.org/mozilla-central/rev/a5f0bad7a33a
Status: REOPENED → RESOLVED
Closed: 7 years ago → 7 years ago
Resolution: --- → FIXED
Updated•7 years ago
|
Blocks: StringCleaning
Updated•4 years ago
|
Component: String → XPCOM
You need to log in
before you can comment on or make changes to this bug.
Description
•