Closed Bug 481677 Opened 16 years ago Closed 16 years ago

Avoid hash lookups in XPCWrappedNative::GetNewOrUsed

Categories

(Core :: XPConnect, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9.2a1

People

(Reporter: peterv, Assigned: peterv)

References

Details

Attachments

(1 file, 4 obsolete files)

Attached patch v1 (obsolete) — Splinter Review
When we have a nsWrapperCache and we get into XPCWrappedNative::GetNewOrUsed we're sure that we don't have a wrapper, so no need to look it up in the hash. We can also avoid an addref/release pair on the identity object if we transfer the pointer from the local identity nsCOMPtr to the wrapper instead of addrefing in the wrapper and releasing from the nsCOMPtr. This came up in bug 481131, comment 11. Bz, any chance you could try if this patch helps with that testcase?
Component: XPConnect → Build Config
Component: Build Config → XPConnect
OK, on the same toc.js the breakdown for GetNewOrUsed now is: 7% self 20% XPCWrappedNative::FindTearOff 9% XPCWrappedNative::Init 9% XPCWrappedNativeProto::GetNewOrUsed 8% QI 8% nsDOMClassInfo::PostCreate 7% operator new 4% JS_DHashTableOperate 4% XPCWrappedNative::GatherScriptableCreateInfo 4% nsElementSH::PostCreate 3% nsContentListSH::PreCreate 2% PR_EnterMonitor 1% PR_ExitMonitor 1% PR_AtomicIncrement 1% nsNodeSH::PreCreate 0.6% ~nsCOMPtr So it looks like this does help with the extra release (cycle collector stuff) and reduces the JS_DHashTableOperate time. There might have been a 1-2% win on the wall-clock time on toc.js and dfn.js. Hard to say because the test is so noisy....
Oh, less monitor time used too; presumably due to not locking around the hashtable get. Would it make sense to pass in an already_AddRefed instead of an nsCOMPtr, and then pass forget() on the relevant comptr and just do an initializer-style assign in the constructor?
That would make it very clear that |identity| is null, fwiw.
It would, yes. I gave up on it after I found out that the specialized nsCOMPtr<nsISupports> doesn't have the forget() that returns already_AddRefed. I guess I can add it, wanted to minimize the changes so we could take this on branch, but that's fairly risk-free.
Attached patch v1.1 (obsolete) — Splinter Review
Attachment #365680 - Attachment is obsolete: true
Attachment #365872 - Flags: superreview?(bzbarsky)
Attachment #365872 - Flags: review?(jst)
Comment on attachment 365872 [details] [diff] [review] v1.1 Want to add "unified = 8" to your [diff] section in .hgrc so that you mq patches have nice context? >+++ b/js/src/xpconnect/src/xpcprivate.h > GetNewOrUsed(XPCCallContext& ccx, > nsISupports* Object, > XPCWrappedNativeScope* Scope, > XPCNativeInterface* Interface, >+ nsWrapperCache* cache, Document that cache can only be non-null if cache->GetWrapper() is null? >+++ b/js/src/xpconnect/src/xpcwrappednative.cpp > XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx, And assert that at entry to this function, please. I'd like to see a diff -w of this file, with the 8-line context; reviewing the diff as it stands is pretty hard. Other than that, looks good.
Attached patch v1.2 (obsolete) — Splinter Review
(In reply to comment #6) > Document that cache can only be non-null if cache->GetWrapper() is null? I've added a comment that the nsWrapperCache should be passed in (not an error if it isn't) and that if a cache is passed in then cache->GetWrapper() must be null. > And assert that at entry to this function, please. Moved the assert to the top of the function. > I'd like to see a diff -w of this file, with the 8-line context; reviewing the > diff as it stands is pretty hard. I'd tried diff -w, it doesn't make it any clearer but here it is.
Attachment #365872 - Attachment is obsolete: true
Attachment #365986 - Flags: superreview?(bzbarsky)
Attachment #365986 - Flags: review?(jst)
Attachment #365872 - Flags: superreview?(bzbarsky)
Attachment #365872 - Flags: review?(jst)
That looks like an hg diff -w. How about something like this: [extensions] extdiff = [extdiff] cmd.wdiff = diff opts.wdiff = -p -U 8 -w -r -N Then wdiff the file?
(oh and hg's built in -w option to diff is known-broken).
Attached patch v1.2 (diff -w) (obsolete) — Splinter Review
Ah, better.
Attachment #365986 - Flags: superreview?(bzbarsky) → superreview+
Comment on attachment 365986 [details] [diff] [review] v1.2 - In XPCWrappedNative::GetNewOrUsed(): - wrapper = new XPCWrappedNative(identity, proto); + wrapper = new XPCWrappedNative(identity.forget(), proto); if(!wrapper) return NS_ERROR_FAILURE; } else { AutoMarkingNativeSetPtr set(ccx); set = XPCNativeSet::GetNewOrUsed(ccx, nsnull, Interface, 0); if(!set) return NS_ERROR_FAILURE; - wrapper = new XPCWrappedNative(identity, Scope, set); + wrapper = new XPCWrappedNative(identity.forget(), Scope, set); Those two changes will cause a leak if we run out of memory right? Also, I think the fact that identity is nulled out from this point on is worthy of a comment so we don't down the road end up trying to use identity later on in this function. r=jst with that looked into.
Attachment #365986 - Flags: review?(jst) → review+
Attached patch v1.3Splinter Review
Had to back out due to orange, needs a small change: we need to addref the wrapper if we get it from the cache after the call to PreCreate.
Attachment #365986 - Attachment is obsolete: true
Attachment #366097 - Attachment is obsolete: true
Attachment #368280 - Flags: superreview+
Attachment #368280 - Flags: review+
Status: ASSIGNED → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
Comment on attachment 368280 [details] [diff] [review] v1.3 Would like to take this on branch, it's a small performance improvement in XPConnect. There's no testsuite for the performance improvement, our existing testsuites already cover the correctness of this change.
Attachment #368280 - Flags: approval1.9.1?
(In reply to comment #13) > (From update of attachment 368280 [details] [diff] [review]) > There's no testsuite for the performance improvement Can you attach a test case? I am working on something to cover stuff like this.
Comment on attachment 368280 [details] [diff] [review] v1.3 a191=drivers. Would like to see more comprehensive testing, but taking your assurances (and sayrer's comment).
Attachment #368280 - Flags: approval1.9.1? → approval1.9.1+
Component: Build Config → XPConnect
This apparently caused a Tp reduction on XP - yay, you!
And also apparently caused a Twinopen regression on XP. :-( See "Talos Regression: Txul increase 3.56% on XP 1.9.1" thread in m.d.tree-management. Backed out, watching to see if the regression goes away. Backout: http://hg.mozilla.org/releases/mozilla-1.9.1/rev/d47dbd3488f9
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Keywords: fixed1.9.1
This wasn't backed out on trunk afaict.
Status: REOPENED → RESOLVED
Closed: 16 years ago16 years ago
Resolution: --- → FIXED
Hmm, well, now that you mention it it also looks like Twinopen regressed on trunk as well: http://graphs.mozilla.org/#show=2420846,2419200,2417613 The automated scripts didn't alert about it, but it looks like a regression. Oddly, it's dropped back down today, but there were some landings in the window that could potentially have improved things. So, I think this should be unfortunately be backed out on trunk as well.
Attachment #368280 - Flags: approval1.9.1+
Comment on attachment 368280 [details] [diff] [review] v1.3 Txul regression fixed. I'm not going to track down why, the patch is simple enough and I don't see anything obvious that can cause that regression. Clearing 1.9.1 approval.
(In reply to comment #21) > Hmm, well, now that you mention it it also looks like Twinopen regressed on > trunk as well: > > http://graphs.mozilla.org/#show=2420846,2419200,2417613 > So, I think this should be unfortunately be backed out on trunk as well. I'll try that, but I don't really see a clear regression on trunk around the time that this patch landed (March 19th).
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Doh. Sorry, my mistake. :-( I didn't notice this landed on trunk almost exactly 1 month before it landed on branch. The comments here on 3/22 and 4/21 are not 1 day apart! And the coincidental clear regression on trunk is not so coincidental after all, because the graph I linked to is for branch. So, I'm not sure WTF I was smoking. Trunk looks fine, no backout needed. *sigh*
Status: REOPENED → RESOLVED
Closed: 16 years ago16 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: