Bug 87938

Summary: [GTK] Avoid unnecessary heap allocations during drag and drop operations
Product: WebKit Reporter: Carlos Garcia Campos <cgarcia>
Component: WebKitGTKAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: gustavo, mrobinson, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: Linux   
Attachments:
Description Flags
Patch
mrobinson: review-
Updated patch to apply on current git master mrobinson: review+

Carlos Garcia Campos
Reported 2012-05-31 01:10:33 PDT
The DragAndDropHelper returns a new allocated DragData object in several methods, while the only thing we need is the platformData (DataObjectGtk). So we could just return a pointer and create the DragData object in the stack
Attachments
Patch (14.29 KB, patch)
2012-05-31 01:17 PDT, Carlos Garcia Campos
mrobinson: review-
Updated patch to apply on current git master (14.24 KB, patch)
2012-12-03 07:58 PST, Carlos Garcia Campos
mrobinson: review+
Carlos Garcia Campos
Comment 1 2012-05-31 01:17:11 PDT
WebKit Review Bot
Comment 2 2012-05-31 01:19:40 PDT
Thanks for the patch. If this patch contains new public API please make sure it follows the guidelines for new WebKit2 GTK+ API. See http://trac.webkit.org/wiki/WebKitGTK/AddingNewWebKit2API
Martin Robinson
Comment 3 2012-05-31 06:07:35 PDT
Comment on attachment 145013 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=145013&action=review Hrm. I'm not sure if I prefer the new approach. It does avoid an allocation on the heap, but replaces it with an allocation on the stack which is arguably riskier and with the result of creating more code. Additionally this moves from two places in the code having to create DragData to six. I worry also that the use of position as an in and out parameter could be confusing and would prefer to simply have a getter on DragAndDropHelper. > Source/WebCore/platform/gtk/GtkDragAndDropHelper.cpp:161 > - return adoptPtr(static_cast<DragData*>(0)); > + return 0; > I'm not sure what I was thinking when I wrote this code. This should be return nullptr here.
Martin Robinson
Comment 4 2012-05-31 06:09:07 PDT
Comment on attachment 145013 [details] Patch An alternative approach would be to cache the DragData in DragData in DragAndDropHelper.
Carlos Garcia Campos
Comment 5 2012-05-31 08:16:20 PDT
Look at how other ports use it, all of them create a DragData in the stack when needed, because I think it's thought as a temporary object.
Carlos Garcia Campos
Comment 6 2012-05-31 08:25:16 PDT
(In reply to comment #3) > (From update of attachment 145013 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=145013&action=review > > Hrm. I'm not sure if I prefer the new approach. It does avoid an allocation on the heap, but replaces it with an allocation on the stack which is arguably riskier and with the result of creating more code. Additionally this moves from two places in the code having to create DragData to six. > > I worry also that the use of position as an in and out parameter could be confusing and would prefer to simply have a getter on DragAndDropHelper. > That's a workaround to use the last motion position instead of the coords passed to drag-data-received, the caller has everything required to build a DragData.
Carlos Garcia Campos
Comment 7 2012-06-01 08:54:19 PDT
DragData has a small size so I don't think there's any risk in allocate it on the stack, and it's what all other ports do after all.
Martin Robinson
Comment 8 2012-06-01 08:59:59 PDT
(In reply to comment #7) > DragData has a small size so I don't think there's any risk in allocate it on the stack, and it's what all other ports do after all. It still seems like this is less clean than the old approach. An allocation on the heap isn't such a terrible thing, but even so it can be eliminated by simply caching the DragData in the DragAndDropHelper.
Carlos Garcia Campos
Comment 9 2012-06-01 09:03:17 PDT
(In reply to comment #8) > (In reply to comment #7) > > DragData has a small size so I don't think there's any risk in allocate it on the stack, and it's what all other ports do after all. > > It still seems like this is less clean than the old approach. An allocation on the heap isn't such a terrible thing, but even so it can be eliminated by simply caching the DragData in the DragAndDropHelper. Well, I don't see this is less clean, and DragData looks like a temp object to me, so I prefer not to cache it at all.
Carlos Garcia Campos
Comment 10 2012-12-03 07:58:28 PST
Created attachment 177257 [details] Updated patch to apply on current git master Let's give this another try, I still think the code is simpler, more efficient and consistent with *all* other ports in both WebKit1 and WebKit2.
Carlos Garcia Campos
Comment 11 2012-12-04 02:34:02 PST
Note You need to log in before you can comment on or make changes to this bug.