RESOLVED FIXED 122516
Avoid resizing the internal buffer of SharedBuffer when creating a PurgeableBuffer
https://bugs.webkit.org/show_bug.cgi?id=122516
Summary Avoid resizing the internal buffer of SharedBuffer when creating a PurgeableB...
Daniel Bates
Reported 2013-10-08 12:38:43 PDT
Currently we may flatten the SharedBuffer segments into the internal buffer of the SharedBuffer before creating a PurgeableBuffer. As a result we may need to resize the internal buffer of the SharedBuffer to fit the contents of its segments. We can avoid this resize operation by allocating a PurgeableBuffer and copying the SharedBuffer's internal buffer and segments directly into it.
Attachments
Patch (8.17 KB, patch)
2013-10-08 12:48 PDT, Daniel Bates
no flags
Patch (8.32 KB, patch)
2013-10-08 15:21 PDT, Daniel Bates
no flags
Patch (8.95 KB, patch)
2013-10-08 15:44 PDT, Daniel Bates
no flags
Patch (8.98 KB, patch)
2013-10-08 15:45 PDT, Daniel Bates
no flags
Patch (8.87 KB, patch)
2013-10-08 16:01 PDT, Daniel Bates
darin: review+
Daniel Bates
Comment 1 2013-10-08 12:48:24 PDT
EFL EWS Bot
Comment 2 2013-10-08 12:53:16 PDT
EFL EWS Bot
Comment 3 2013-10-08 12:55:30 PDT
Darin Adler
Comment 4 2013-10-08 12:56:14 PDT
Comment on attachment 213708 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=213708&action=review I like the direction this patch is going, but there are some details I think you should fix. > Source/WebCore/platform/PurgeableBuffer.h:38 > + static PassOwnPtr<PurgeableBuffer> create(size_t); I think we should follow the pattern for String::createUninitialized here. Use an out argument for the pointer and use the word “uninitialized” in the name of the function. I also suggest including the makePurgeable(false) in that function instead of doing it at the call site. > Source/WebCore/platform/PurgeableBuffer.h:44 > + char* data(); I think it would be better to pass the non-const char* out of the create function rather than always exposing a non-const data pointer after the fact on all purgeable buffers. So please change this back. > Source/WebCore/platform/SharedBuffer.cpp:383 > +void SharedBuffer::copySegmentsOrDataArrayAndClear(char* destination, unsigned bytesToCopy) const Is there any caller of copyDataArrayAndClear that does not want this behavior? Why do we need a separate function for this?
Daniel Bates
Comment 5 2013-10-08 14:55:00 PDT
(In reply to comment #4) > [...] > > Source/WebCore/platform/PurgeableBuffer.h:38 > > + static PassOwnPtr<PurgeableBuffer> create(size_t); > > I think we should follow the pattern for String::createUninitialized here. Use an out argument for the pointer and use the word “uninitialized” in the name of the function. I like this idiom. Will modify patch. > I also suggest including the makePurgeable(false) in that function instead of doing it at the call site. By adopting the createUninitialized idiom, it seems sufficient to omit this check as we create the PurgeableBuffer in a non-volatile state by default. For some reason, I thought that adding this check at the call site would make the usage of PurgeableBuffer::create(size_t) and the code that writes directly into its buffer less error prone or at least consistent consistent with the document usage for PurgeableBuffer::data(). The new name PurgeableBuffer::createUninitialized(...) seems to obviate the need for such a check since the name better conveys to the caller the state of the PurgeableBuffer. That is, it is uninitialized and hence there is an assumption that it's non-volatile. Do you see a benefit in explicitly checking/asserting makePurgeable(false) is true in PurgeableBuffer::createUninitialized()? > > > Source/WebCore/platform/PurgeableBuffer.h:44 > > + char* data(); > > I think it would be better to pass the non-const char* out of the create function rather than always exposing a non-const data pointer after the fact on all purgeable buffers. So please change this back. > Will revert this change. > > Source/WebCore/platform/SharedBuffer.cpp:383 > > +void SharedBuffer::copySegmentsOrDataArrayAndClear(char* destination, unsigned bytesToCopy) const > > Is there any caller of copyDataArrayAndClear that does not want this behavior? Why do we need a separate function for this? Will remove function copySegmentsOrDataArrayAndClear. Instead, will move the !USE(NETWORK_CFDATA_ARRAY_CALLBACK)-guarded code in copySegmentsOrDataArrayAndClear() into a !USE(NETWORK_CFDATA_ARRAY_CALLBACK)-guarded version of copyDataArrayAndClear() such that SharedBuffer.h will declare a platform-independent function called copyDataArrayAndClear, SharedBuffer.cpp will provide the platform-independent implementation of this function and SharedBufferCF.cp will provide a CF-specific implementation of this function.
Daniel Bates
Comment 6 2013-10-08 15:21:27 PDT
EFL EWS Bot
Comment 7 2013-10-08 15:34:29 PDT
EFL EWS Bot
Comment 8 2013-10-08 15:41:02 PDT
Daniel Bates
Comment 9 2013-10-08 15:44:29 PDT
Daniel Bates
Comment 10 2013-10-08 15:45:06 PDT
EFL EWS Bot
Comment 11 2013-10-08 15:49:48 PDT
EFL EWS Bot
Comment 12 2013-10-08 15:51:43 PDT
kov's GTK+ EWS bot
Comment 13 2013-10-08 15:58:27 PDT
Daniel Bates
Comment 14 2013-10-08 16:01:48 PDT
Darin Adler
Comment 15 2013-10-08 22:17:38 PDT
Comment on attachment 213729 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=213729&action=review > Source/WebCore/platform/SharedBuffer.cpp:233 > + char* destination = nullptr; I don’t think this needs to be initialized. > Source/WebCore/platform/mac/PurgeableBufferMac.cpp:86 > + char* buffer = allocatePurgeableBuffer(size); > + if (!buffer) > + return nullptr; > + memcpy(buffer, data, size); > + return adoptPtr(new PurgeableBuffer(buffer, size)); Seems like this could just call createUninitialized and then do the memcpy. No need for the allocatePurgeableBuffer function at all.
Daniel Bates
Comment 16 2013-10-10 11:18:25 PDT
(In reply to comment #15) > (From update of attachment 213729 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=213729&action=review > > > Source/WebCore/platform/SharedBuffer.cpp:233 > > + char* destination = nullptr; > > I don’t think this needs to be initialized. Will fix. > > > Source/WebCore/platform/mac/PurgeableBufferMac.cpp:86 > > + char* buffer = allocatePurgeableBuffer(size); > > + if (!buffer) > > + return nullptr; > > + memcpy(buffer, data, size); > > + return adoptPtr(new PurgeableBuffer(buffer, size)); > > Seems like this could just call createUninitialized and then do the memcpy. No need for the allocatePurgeableBuffer function at all. Will remove function allocatePurgeableBuffer() and implement PurgeableBuffer::create() in terms of PurgeableBuffer::createUninitialized().
Daniel Bates
Comment 17 2013-10-10 11:19:11 PDT
Note You need to log in before you can comment on or make changes to this bug.