Closed
Bug 410223
Opened 17 years ago
Closed 16 years ago
Avoid extra allocations in WrappedNative2WrapperMap
Categories
(Core :: XPConnect, defect, P1)
Tracking
()
RESOLVED
FIXED
mozilla1.9beta4
People
(Reporter: mrbkap, Assigned: mrbkap)
References
Details
(Keywords: perf)
Attachments
(3 files, 2 obsolete files)
4.60 KB,
patch
|
jst
:
review+
jst
:
superreview+
|
Details | Diff | Splinter Review |
2.49 KB,
patch
|
mrbkap
:
review+
mrbkap
:
superreview+
|
Details | Diff | Splinter Review |
6.19 KB,
patch
|
Details | Diff | Splinter Review |
See bug 399587, comment 6 where jst suggests that we store Links in the entries themselves as opposed to pointers to Links that are allocated elsewhere.
Updated•17 years ago
|
Version: unspecified → Trunk
Assignee | ||
Comment 1•17 years ago
|
||
This should do it.
Assignee: nobody → mrbkap
Status: NEW → ASSIGNED
Attachment #295464 -
Flags: superreview?(brendan)
Attachment #295464 -
Flags: review?(brendan)
Comment 2•17 years ago
|
||
Comment on attachment 295464 [details] [diff] [review] Fix >@@ -662,12 +662,25 @@ WrappedNative2WrapperMap::ClearLink(JSDH > { > Entry* e = static_cast<Entry*>(entry); > e->key = nsnull; >- if(e->value) >- { >- PR_REMOVE_LINK(e->value); >- delete e->value; >- e->value = nsnull; >- } >+ PR_REMOVE_LINK(&e->value); >+ memset(e, 0, sizeof(*e)); Could use a free pattern instead of 0, and only if DEBUG -- the caller in jsdhash/pldhash is going to free the double hashtable to the malloc heap shortly. >@@ -687,6 +700,7 @@ WrappedNative2WrapperMap::WrappedNative2 > { > sOps = *JS_DHashGetStubOps(); > sOps.clearEntry = WrappedNative2WrapperMap::ClearLink; >+ sOps.moveEntry = WrappedNative2WrapperMap::CopyLink; > } I whined to mrbkap in person about static init for sOps avoiding this code footprint micro-hit altogether; the counter-argument is that the ops struct layout might change, but that's pretty unlikely and adding more dependencies on it raises the tax threat, reducing the odds even more over time ;-). Righteous static_cast goodness. /be
Attachment #295464 -
Flags: superreview?(brendan)
Attachment #295464 -
Flags: superreview+
Attachment #295464 -
Flags: review?(brendan)
Attachment #295464 -
Flags: review+
Assignee | ||
Comment 3•17 years ago
|
||
I couldn't use a free pattern because we test that memory for null later (since entries can be reused). This switches over to static initialization. I'll check it in post-haste.
Attachment #295464 -
Attachment is obsolete: true
Attachment #298810 -
Flags: superreview+
Attachment #298810 -
Flags: review+
Assignee | ||
Comment 4•17 years ago
|
||
Comment on attachment 298810 [details] [diff] [review] Updated to comments Oops, thought this was blocking. This patch should help reduce malloc noise and may help fix bug 410291.
Attachment #298810 -
Flags: approval1.9?
Comment 5•17 years ago
|
||
Comment on attachment 298810 [details] [diff] [review] Updated to comments a+ for sure - get it in!
Attachment #298810 -
Flags: approval1.9? → approval1.9+
Updated•17 years ago
|
Flags: blocking1.9+
Priority: -- → P1
Updated•17 years ago
|
Keywords: checkin-needed
Assignee | ||
Comment 6•17 years ago
|
||
Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
Updated•17 years ago
|
Keywords: checkin-needed
Assignee | ||
Comment 7•17 years ago
|
||
I had to back this out because it caused mochitests to crash.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Updated•16 years ago
|
Target Milestone: --- → mozilla1.9beta4
Assignee | ||
Comment 8•16 years ago
|
||
The crashing was, in turn, caused by memory corruption because of the moveEntry hook I added. Here's a potential fix, but I don't really like the const_cast (I don't see a way around it, though, am I missing anything?). diff --git a/js/src/xpconnect/src/xpcmaps.cpp b/js/src/xpconnect/src/xpcmaps.cpp --- a/js/src/xpconnect/src/xpcmaps.cpp +++ b/js/src/xpconnect/src/xpcmaps.cpp @@ -682,15 +682,15 @@ WrappedNative2WrapperMap::CopyLink(JSDHa const JSDHashEntryHdr* from, JSDHashEntryHdr* to) { - const Entry* oldEntry = static_cast<const Entry*>(from); + Entry* oldEntry = const_cast<Entry*>(static_cast<const Entry*>(from)); Entry* newEntry = static_cast<Entry*>(to); newEntry->key = oldEntry->key; newEntry->value = oldEntry->value; // Now update the list. - newEntry->value.next->prev = &newEntry->value; - newEntry->value.prev->next = &newEntry->value; + PR_INSERT_LINK(&newEntry->value, &oldEntry->value); + PR_REMOVE_LINK(&oldEntry->value); } // static brendan: what do you think?
Status: REOPENED → ASSIGNED
Comment 9•16 years ago
|
||
Over-used const, sorry -- file a bug? /be
Assignee | ||
Comment 10•16 years ago
|
||
Here's the patch that I'll check in the next time I have time.
Attachment #298810 -
Attachment is obsolete: true
Attachment #301972 -
Flags: superreview?(brendan)
Attachment #301972 -
Flags: review?(brendan)
Assignee | ||
Comment 11•16 years ago
|
||
I filed bug 416200 on making |from| not const in moveEntry.
Comment 12•16 years ago
|
||
Comment on attachment 301972 [details] [diff] [review] Now with less crashing >+WrappedNative2WrapperMap::MoveLink(JSDHashTable* table, >+ const JSDHashEntryHdr* from, >+ JSDHashEntryHdr* to) >+{ >+ Entry* oldEntry = const_cast<Entry*>(static_cast<const Entry*>(from)); FIXME comment? >+ Entry* newEntry = static_cast<Entry*>(to); >+ >+ newEntry->key = oldEntry->key; >+ newEntry->value = oldEntry->value; >+ >+ // Now update the list. >+ PR_INSERT_LINK(&newEntry->value, &oldEntry->value); >+ PR_REMOVE_LINK(&oldEntry->value); Comment detail needed? This is confusing looking, but it's correct. /be
Attachment #301972 -
Flags: superreview?(brendan)
Attachment #301972 -
Flags: superreview+
Attachment #301972 -
Flags: review?(brendan)
Attachment #301972 -
Flags: review+
Comment 13•16 years ago
|
||
Comment on attachment 301972 [details] [diff] [review] Now with less crashing Blake, that only fixes part of the problem, there's a similar problem in WrappedNative2WrapperMap::Add() as well. With both fixed, I can run through mochitest w/o crashes. I'll attach a followup diff, and there's a way to fix CopyLink() w/o violating the constness of the old entry, bogus or not.
Attachment #301972 -
Flags: superreview-
Attachment #301972 -
Flags: superreview+
Attachment #301972 -
Flags: review-
Attachment #301972 -
Flags: review+
Comment 14•16 years ago
|
||
Blake, this applies on top of your latest fix and fixes the problem in Add() and doesn't violate the const argument. Violating the const argument does let you write code that makes more sense, so I don't really care either way there... And this also changes the XOW code to use a better named reserved slot constant in a couple of places.
Attachment #302004 -
Flags: superreview?(mrbkap)
Attachment #302004 -
Flags: review?(mrbkap)
Comment 15•16 years ago
|
||
Comment on attachment 301972 [details] [diff] [review] Now with less crashing Um, shouldn't have r-'ed this patch, as it's still a good change, just missed one spot.
Attachment #301972 -
Flags: superreview-
Attachment #301972 -
Flags: superreview+
Attachment #301972 -
Flags: review-
Attachment #301972 -
Flags: review+
Assignee | ||
Comment 16•16 years ago
|
||
Comment on attachment 302004 [details] [diff] [review] Additional change needed... >diff --git a/js/src/xpconnect/src/XPCCrossOriginWrapper.cpp b/js/src/xpconnect>- return JS_SetReservedSlot(cx, xow, XPCWrapper::sNumSlots, >+ return JS_SetReservedSlot(cx, xow, XPC_XOW_ScopeSlot, > PRIVATE_TO_JSVAL(newScope)) && I missed the declaration of XPC_XOW_ScopeSlot in this patch, but I believe you. >diff --git a/js/src/xpconnect/src/xpcmaps.cpp b/js/src/xpconnect/src/xpcmaps.cpp > // Now update the list. >- PR_INSERT_LINK(&newEntry->value, &oldEntry->value); >- PR_REMOVE_LINK(&oldEntry->value); >+ if (PR_CLIST_IS_EMPTY(&oldEntry->value)) { >+ PR_INIT_CLIST(&newEntry->value); Need to initialize newEntry->value.obj here. Also, being in xpcmaps.cpp, need to cuddle the |if| and ( and { gets its own line. >@@ -728,7 +732,12 @@ WrappedNative2WrapperMap::Add(WrappedNative2WrapperMap* head, >+ if (!l->next) >+ PR_INIT_CLIST(l); Cuddle if and (? Also, comment here that this only happens when |this == head|. I wasn't hitting this case in the mochitests, but it's definitely needed. r+sr=me with those things fixed.
Attachment #302004 -
Flags: superreview?(mrbkap)
Attachment #302004 -
Flags: superreview+
Attachment #302004 -
Flags: review?(mrbkap)
Attachment #302004 -
Flags: review+
Comment 17•16 years ago
|
||
Comment 18•16 years ago
|
||
Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 17 years ago → 16 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•