Bug 73784

Summary: Use HashMap<OwnPtr> in CollectionCache
Product: WebKit Reporter: Darin Adler <darin>
Component: DOMAssignee: Darin Adler <darin>
Status: RESOLVED FIXED    
Severity: Normal CC: koivisto
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 73757    
Attachments:
Description Flags
Patch kling: review+

Darin Adler
Reported 2011-12-04 15:25:33 PST
Use HashMap<OwnPtr> in CollectionCache
Attachments
Patch (7.90 KB, patch)
2011-12-04 15:27 PST, Darin Adler
kling: review+
Darin Adler
Comment 1 2011-12-04 15:27:30 PST
Andreas Kling
Comment 2 2011-12-04 18:35:29 PST
Comment on attachment 117812 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=117812&action=review > Source/WebCore/html/HTMLCollection.cpp:344 > + OwnPtr<Vector<Element*> >& nameVector = m_info->nameCache.add(nameAttrVal.impl(), nullptr).first->second; > + if (!nameVector) > + nameVector = adoptPtr(new Vector<Element*>); Given how much this pattern repeats, it seems like we could factor them into functions, e.g ensureNameCache() and ensureIdCache(). That would also make the "// add to foo cache" comments even more redundant.
Darin Adler
Comment 3 2011-12-05 15:40:26 PST
Comment on attachment 117812 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=117812&action=review >> Source/WebCore/html/HTMLCollection.cpp:344 >> + nameVector = adoptPtr(new Vector<Element*>); > > Given how much this pattern repeats, it seems like we could factor them into functions, e.g ensureNameCache() and ensureIdCache(). > That would also make the "// add to foo cache" comments even more redundant. I think I can make a helper function that we can use at all 6 call sites.
Darin Adler
Comment 4 2011-12-06 09:30:06 PST
Antti Koivisto
Comment 5 2011-12-06 09:48:45 PST
Wouldn't it be even better to just to use HashMap<AtomicStringImpl*, Vector<Element*> > ? Do we lack optimization for moving Vectors in HashMaps?
Darin Adler
Comment 6 2011-12-06 10:11:12 PST
(In reply to comment #5) > Wouldn't it be even better to just to use HashMap<AtomicStringImpl*, Vector<Element*> > ? Do we lack optimization for moving Vectors in HashMaps? I don’t know if it would be better. I don’t know how well we accommodate vectors when moving hash table entries around. Also, empty and deleted slots would use a lot more memory than they do for OwnPtr.
Antti Koivisto
Comment 7 2011-12-06 10:16:27 PST
(In reply to comment #6) > I don’t know if it would be better. I don’t know how well we accommodate vectors when moving hash table entries around. Also, empty and deleted slots would use a lot more memory than they do for OwnPtr. Empty vector is a pointer and a size_t. Considering that used values now use more memory the difference shouldn't be huge. Extra indirection is slower and the type looks uglier so it would be nice if the pure vector case was efficient too.
Darin Adler
Comment 8 2011-12-06 10:20:38 PST
(In reply to comment #7) > (In reply to comment #6) > > I don’t know if it would be better. I don’t know how well we accommodate vectors when moving hash table entries around. Also, empty and deleted slots would use a lot more memory than they do for OwnPtr. > > Empty vector is a pointer and a size_t. Considering that used values now use more memory the difference shouldn't be huge. Extra indirection is slower and the type looks uglier so it would be nice if the pure vector case was efficient too. Sure, sounds like a neat project.
Darin Adler
Comment 9 2011-12-06 10:22:26 PST
(In reply to comment #7) > Empty vector is a pointer and a size_t. I believe it’s a pointer (m_buffer) and two size_t's (m_capacity and m_size).
Antti Koivisto
Comment 10 2011-12-06 10:35:35 PST
(In reply to comment #9) > (In reply to comment #7) > > Empty vector is a pointer and a size_t. > > I believe it’s a pointer (m_buffer) and two size_t's (m_capacity and m_size). You are right. Optimizing m_capacity away from Vector in null case might be a good memory win.
Note You need to log in before you can comment on or make changes to this bug.