RESOLVED FIXED Bug 233030
Distinguish contiguous SharedBuffer from non-contiguous one and guarantee immutability
https://bugs.webkit.org/show_bug.cgi?id=233030
Summary Distinguish contiguous SharedBuffer from non-contiguous one and guarantee imm...
Jean-Yves Avenard [:jya]
Reported 2021-11-12 00:26:52 PST
SharedBuffer have some const methods, yet they do not guarantee immutability of the object when called. Calling some methods like data() which is defined as: const uint8_t* data() const; will actually combine all DataSegment into one Same for const method combineIntoOneSegment(). SharedBuffer:m_segments shouldn't be mutable. What we could have instead is a SharedBuffer base class with a ContiguousSharedBuffer inheriting from it. data() would only be available with ContiguousSharedBuffer. SharedBuffer would have a makeContiguous() const returning a ContiguousSharedBuffer (or itself if already contiguous) This would ease tasks such as bug 232424, and guaranteeing immutability would allow for multi-threaded use necessary for doing rdar://84517825.
Attachments
WIP (387.98 KB, patch)
2021-11-18 06:44 PST, Jean-Yves Avenard [:jya]
no flags
WIP (398.06 KB, patch)
2021-11-19 02:08 PST, Jean-Yves Avenard [:jya]
no flags
WIP (415.40 KB, patch)
2021-11-21 05:22 PST, Jean-Yves Avenard [:jya]
no flags
Patch for EWS (427.05 KB, patch)
2021-11-21 05:37 PST, Jean-Yves Avenard [:jya]
no flags
WIP Combined Patch for EWS (434.24 KB, patch)
2021-11-21 18:41 PST, Jean-Yves Avenard [:jya]
ews-feeder: commit-queue-
WIP Combined Patch for EWS (437.06 KB, patch)
2021-11-21 19:03 PST, Jean-Yves Avenard [:jya]
no flags
WIP Combined Patch for EWS (455.63 KB, patch)
2021-11-22 02:16 PST, Jean-Yves Avenard [:jya]
no flags
WIP ContiguousSharedBuffer for EWS (362.91 KB, patch)
2021-11-22 20:46 PST, Jean-Yves Avenard [:jya]
no flags
WIP ContiguousSharedBuffer for EWS (362.95 KB, patch)
2021-11-22 21:14 PST, Jean-Yves Avenard [:jya]
no flags
WIP ContiguousSharedBuffer for EWS (374.01 KB, patch)
2021-11-22 21:18 PST, Jean-Yves Avenard [:jya]
ews-feeder: commit-queue-
WIP ContiguousSharedBuffer for EWS (374.49 KB, patch)
2021-11-22 21:39 PST, Jean-Yves Avenard [:jya]
ews-feeder: commit-queue-
WIP ContiguousSharedBuffer for EWS (374.71 KB, patch)
2021-11-22 21:47 PST, Jean-Yves Avenard [:jya]
ews-feeder: commit-queue-
WIP ContiguousSharedBuffer for EWS (375.43 KB, patch)
2021-11-22 22:01 PST, Jean-Yves Avenard [:jya]
ews-feeder: commit-queue-
WIP ContiguousSharedBuffer for EWS (376.70 KB, patch)
2021-11-22 23:04 PST, Jean-Yves Avenard [:jya]
no flags
WIP ContiguousSharedBuffer for EWS (384.18 KB, patch)
2021-11-23 00:05 PST, Jean-Yves Avenard [:jya]
ews-feeder: commit-queue-
WIP ContiguousSharedBuffer for EWS (384.18 KB, patch)
2021-11-23 00:28 PST, Jean-Yves Avenard [:jya]
ews-feeder: commit-queue-
WIP ContiguousSharedBuffer for EWS (386.11 KB, patch)
2021-11-23 01:20 PST, Jean-Yves Avenard [:jya]
ews-feeder: commit-queue-
WIP ContiguousSharedBuffer for EWS (383.27 KB, patch)
2021-11-23 03:41 PST, Jean-Yves Avenard [:jya]
no flags
WIP ContiguousSharedBuffer for EWS (293.96 KB, patch)
2021-11-24 04:50 PST, Jean-Yves Avenard [:jya]
ews-feeder: commit-queue-
WIP ContiguousSharedBuffer for EWS (399.39 KB, patch)
2021-11-24 05:45 PST, Jean-Yves Avenard [:jya]
ews-feeder: commit-queue-
WIP ContiguousSharedBuffer for EWS (404.21 KB, patch)
2021-11-24 06:03 PST, Jean-Yves Avenard [:jya]
no flags
WIP ContiguousSharedBuffer for EWS (437.11 KB, patch)
2021-11-26 00:51 PST, Jean-Yves Avenard [:jya]
no flags
ContiguousSharedBuffer for EWS (408.21 KB, patch)
2021-11-26 00:54 PST, Jean-Yves Avenard [:jya]
no flags
ContiguousSharedBuffer for review (397.13 KB, patch)
2021-11-26 00:56 PST, Jean-Yves Avenard [:jya]
no flags
Patch (396.93 KB, patch)
2021-11-30 19:23 PST, Jean-Yves Avenard [:jya]
no flags
Patch for EWS (407.98 KB, patch)
2021-11-30 19:33 PST, Jean-Yves Avenard [:jya]
no flags
Patch for EWS (407.99 KB, patch)
2021-12-01 04:27 PST, Jean-Yves Avenard [:jya]
no flags
Patch (407.99 KB, patch)
2021-12-01 04:28 PST, Jean-Yves Avenard [:jya]
no flags
Patch (396.94 KB, patch)
2021-12-01 04:29 PST, Jean-Yves Avenard [:jya]
no flags
Patch (396.97 KB, patch)
2021-12-02 04:06 PST, Jean-Yves Avenard [:jya]
no flags
Patch (398.50 KB, patch)
2021-12-03 16:56 PST, Jean-Yves Avenard [:jya]
no flags
Patch (398.50 KB, patch)
2021-12-03 20:11 PST, Jean-Yves Avenard [:jya]
no flags
Patch (398.41 KB, patch)
2021-12-03 22:32 PST, Jean-Yves Avenard [:jya]
no flags
Patch (398.41 KB, patch)
2021-12-03 23:55 PST, Jean-Yves Avenard [:jya]
no flags
Patch (399.02 KB, patch)
2021-12-03 23:57 PST, Jean-Yves Avenard [:jya]
no flags
Patch (401.54 KB, patch)
2021-12-05 21:21 PST, Jean-Yves Avenard [:jya]
no flags
Patch (404.55 KB, patch)
2021-12-06 21:44 PST, Jean-Yves Avenard [:jya]
ews-feeder: commit-queue-
Patch (404.59 KB, patch)
2021-12-06 22:24 PST, Jean-Yves Avenard [:jya]
no flags
Patch (404.70 KB, patch)
2021-12-06 23:08 PST, Jean-Yves Avenard [:jya]
no flags
Patch (404.82 KB, patch)
2021-12-09 05:17 PST, Jean-Yves Avenard [:jya]
ews-feeder: commit-queue-
Patch (405.43 KB, patch)
2021-12-09 05:46 PST, Jean-Yves Avenard [:jya]
no flags
Patch (410.97 KB, patch)
2021-12-10 14:19 PST, Jean-Yves Avenard [:jya]
no flags
Patch (431.38 KB, patch)
2021-12-11 03:58 PST, Jean-Yves Avenard [:jya]
no flags
Patch (437.91 KB, patch)
2021-12-11 05:12 PST, Jean-Yves Avenard [:jya]
ews-feeder: commit-queue-
Patch (440.05 KB, patch)
2021-12-11 05:40 PST, Jean-Yves Avenard [:jya]
no flags
Patch (436.91 KB, patch)
2021-12-12 03:50 PST, Jean-Yves Avenard [:jya]
no flags
Patch (438.88 KB, patch)
2021-12-12 21:54 PST, Jean-Yves Avenard [:jya]
no flags
Radar WebKit Bug Importer
Comment 1 2021-11-12 00:27:08 PST
Darin Adler
Comment 2 2021-11-16 15:34:34 PST
I like that idea. Analogous with StringBuilder and String.
Jean-Yves Avenard [:jya]
Comment 3 2021-11-16 20:30:51 PST
(In reply to Darin Adler from comment #2) > I like that idea. > > Analogous with StringBuilder and String. I hesitated with going with a SharedBufferWriter ; but the changes required are more invasive. Turned out, that 90% of the SharedBuffer use in webkit are actually only ever made of a single DataSegment. The remaining are all related to networking and receiving the data in chunk. Such SharedBuffer are ultimately always flatten into a contiguous one at the end of its lifecycle, either because they are transferred over IPC, or because the underneath code (such as images) needs a plain buffer. Could revisit the approach you mention.
Jean-Yves Avenard [:jya]
Comment 4 2021-11-16 23:12:41 PST
On second thought, yeah, I see how it can be done easily on top of my current changes.
Darin Adler
Comment 5 2021-11-17 09:41:51 PST
In case this is helpful, some more thoughts: I’m not insisting that you stick so close to the StringBuilder concept, but I do think it’s a really similar relationship. We made String immutable (I did this a long time ago, originally it was not!). It’s possible that we will find that SharedBuffer "builders" could be longer lived than the StringBuilder ever is, though. On the other hand, I don’t see how you "share" something when it’s being mutated!
Jean-Yves Avenard [:jya]
Comment 6 2021-11-18 06:44:22 PST
Jean-Yves Avenard [:jya]
Comment 7 2021-11-19 02:08:00 PST
Jean-Yves Avenard [:jya]
Comment 8 2021-11-21 05:22:34 PST
Jean-Yves Avenard [:jya]
Comment 9 2021-11-21 05:31:41 PST
this patch contains the lot: split ContiguousSharedBuffer from SharedBuffer where data() and the various methods requiring a flat/contiguous SharedBuffer are now only available on ContiguousSharedBuffer Introduce SharedBufferBuilder to create a SharedBuilder the latter now being fully immutable with the exception of takeData which checks if there's only a single ref. though this will likely go away, as the extractData operation isn't atomic and as much not thread-safe. I made most used of SharedBuffer that were only ever used with a single DataSegment a ContiguousSharedBuffer. SharedBuffer that always ended being flatten are now made contiguous when no more buffers would be added to a SharedBuffer. Places that only needed a single conversion to a contiguous buffer are now created at the point of use using makeContiguous I will be splitting this patch in two: one with contiguous buffer only the other with the SharedBufferBuilder this ended up being a much bigger effort than expected.
Jean-Yves Avenard [:jya]
Comment 10 2021-11-21 05:37:48 PST
Created attachment 444925 [details] Patch for EWS
Jean-Yves Avenard [:jya]
Comment 11 2021-11-21 18:41:33 PST
Created attachment 444935 [details] WIP Combined Patch for EWS Fix gtk/windows compilation, handle case where creation of SharedBuffer with a CFData* results in an empty buffer
Jean-Yves Avenard [:jya]
Comment 12 2021-11-21 19:03:35 PST
Created attachment 444936 [details] WIP Combined Patch for EWS gstreamer fixes, more gtk/windows fixes
Jean-Yves Avenard [:jya]
Comment 13 2021-11-22 02:16:04 PST
Created attachment 444951 [details] WIP Combined Patch for EWS more gstreamer and gtk/windows fixes, fix RangeResponseGenerator, fix ScriptBufferSourceProvider : need further thought to StringView not owning its content and to keep alive the flatten SharedBuffer without temporarily doubling memory usage
Jean-Yves Avenard [:jya]
Comment 14 2021-11-22 20:46:30 PST
Created attachment 444997 [details] WIP ContiguousSharedBuffer for EWS More Windows and gstreamer compilation fixes. Fix API test now that call to data() doesn't modify the SharedBuffer
Jean-Yves Avenard [:jya]
Comment 15 2021-11-22 21:14:55 PST
Created attachment 444998 [details] WIP ContiguousSharedBuffer for EWS rebase
Jean-Yves Avenard [:jya]
Comment 16 2021-11-22 21:18:25 PST
Created attachment 444999 [details] WIP ContiguousSharedBuffer for EWS rebase2
Jean-Yves Avenard [:jya]
Comment 17 2021-11-22 21:39:43 PST
Created attachment 445000 [details] WIP ContiguousSharedBuffer for EWS
Jean-Yves Avenard [:jya]
Comment 18 2021-11-22 21:47:11 PST
Created attachment 445002 [details] WIP ContiguousSharedBuffer for EWS
Jean-Yves Avenard [:jya]
Comment 19 2021-11-22 22:01:07 PST
Created attachment 445003 [details] WIP ContiguousSharedBuffer for EWS yet more gstreamer compilation fix, need a build machine really
Jean-Yves Avenard [:jya]
Comment 20 2021-11-22 23:04:02 PST
Created attachment 445005 [details] WIP ContiguousSharedBuffer for EWS iOS sim, SharedBufferWin compilation fixes
Jean-Yves Avenard [:jya]
Comment 21 2021-11-23 00:05:11 PST
Created attachment 445008 [details] WIP ContiguousSharedBuffer for EWS Windows compilation fixes
Jean-Yves Avenard [:jya]
Comment 22 2021-11-23 00:28:37 PST
Created attachment 445011 [details] WIP ContiguousSharedBuffer for EWS
Jean-Yves Avenard [:jya]
Comment 23 2021-11-23 01:20:06 PST
Created attachment 445018 [details] WIP ContiguousSharedBuffer for EWS Windows JPEG decoder compilation fix
Jean-Yves Avenard [:jya]
Comment 24 2021-11-23 03:41:58 PST
Created attachment 445022 [details] WIP ContiguousSharedBuffer for EWS Fix windows wpe crash, hopefully make gtk finally compile
Philippe Normand
Comment 25 2021-11-23 12:41:41 PST
I'm sorry I didn't have time to check this, I can check the gtk/wpe build and attach additional fixes here...
Philippe Normand
Comment 26 2021-11-23 14:08:41 PST
Jean-Yves Avenard [:jya]
Comment 27 2021-11-23 15:18:31 PST
(In reply to Philippe Normand from comment #26) > GTK/WPE fixes http://sprunge.us/vmcu7f Thanks ! was taking me forever with only one error reported at a time :) I believe some makeContiguous() are unnecessary as the original buffer already is.
Jean-Yves Avenard [:jya]
Comment 28 2021-11-23 19:43:01 PST
(In reply to Philippe Normand from comment #26) > GTK/WPE fixes http://sprunge.us/vmcu7f When doing things like: > // FIXME: ideally we would encode the content as a stream without having to fetch it all. > - auto* data = resource.data->data(); > + auto* data = resource.data->makeContiguous()->data(); data would be a dangling pointer once the expression is evaluated.
Jean-Yves Avenard [:jya]
Comment 29 2021-11-23 20:05:07 PST
I wonder if such an incorrect use should warrant data() to make data() && = delete It's going to be quite painful for some use, but that would be an easy mistake or have data return an object that is refcounted itself.
Jean-Yves Avenard [:jya]
Comment 30 2021-11-24 04:50:36 PST
Created attachment 445087 [details] WIP ContiguousSharedBuffer for EWS wpe and gtk fixes
Jean-Yves Avenard [:jya]
Comment 31 2021-11-24 05:45:23 PST
Created attachment 445091 [details] WIP ContiguousSharedBuffer for EWS last gtk fixes
Jean-Yves Avenard [:jya]
Comment 32 2021-11-24 06:03:52 PST
Created attachment 445095 [details] WIP ContiguousSharedBuffer for EWS uploaded wrong stack of patches
EWS Watchlist
Comment 33 2021-11-24 06:04:45 PST
Thanks for the patch. If this patch contains new public API please make sure it follows the guidelines for new WebKit2 GTK+ API. See https://trac.webkit.org/wiki/WebKitGTK/AddingNewWebKit2API
Jean-Yves Avenard [:jya]
Comment 34 2021-11-26 00:51:27 PST
Created attachment 445179 [details] WIP ContiguousSharedBuffer for EWS final preliminary version
Jean-Yves Avenard [:jya]
Comment 35 2021-11-26 00:54:52 PST
Created attachment 445180 [details] ContiguousSharedBuffer for EWS final preliminary version
Jean-Yves Avenard [:jya]
Comment 36 2021-11-26 00:56:04 PST
Created attachment 445181 [details] ContiguousSharedBuffer for review
Darin Adler
Comment 37 2021-11-29 09:54:20 PST
This is a great idea. One thing I don’t like about this change is that the simpler case, the contiguous buffer, has the longer name. I would call the contiguous immutable one by the shorter name and rename the more complex mutable one that supports segments.
Jean-Yves Avenard [:jya]
Comment 38 2021-11-29 16:03:18 PST
(In reply to Darin Adler from comment #37) > This is a great idea. > > One thing I don’t like about this change is that the simpler case, the > contiguous buffer, has the longer name. I would call the contiguous > immutable one by the shorter name and rename the more complex mutable one > that supports segments. After bug 233442 (introducing SharedBufferBuilder), neither will be mutable.
Jean-Yves Avenard [:jya]
Comment 39 2021-11-29 16:53:46 PST
What about SharedBuffer which by default is a contiguous one and is the base class. And CompositeSharedBuffer ? there will be a need to reshuffle the logic a bit as there's a lot of place in the code that are expecting a SharedBuffer as base class. Would make the change even more massive. Probably would be simpler still to have CompositeSharedBuffer be the base class and SharedBuffer inherit from it.
Darin Adler
Comment 40 2021-11-30 09:14:39 PST
I guess we can do the renames as mechanical steps later. I’d like to make sure the most-commonly-used class has the shortest name.
Jean-Yves Avenard [:jya]
Comment 41 2021-11-30 19:23:36 PST
Created attachment 445502 [details] Patch rebase following bug 233471
Jean-Yves Avenard [:jya]
Comment 42 2021-11-30 19:33:51 PST
Created attachment 445504 [details] Patch for EWS
Jean-Yves Avenard [:jya]
Comment 43 2021-11-30 20:17:38 PST
(In reply to Darin Adler from comment #40) > I guess we can do the renames as mechanical steps later. I’d like to make > sure the most-commonly-used class has the shortest name. I will be taking this in a follow-up patch. That will make review more readable. Will land all three patches at once. So I believe the patch as-is, is ready for review.
Jean-Yves Avenard [:jya]
Comment 44 2021-11-30 20:23:06 PST
(In reply to Darin Adler from comment #40) > I guess we can do the renames as mechanical steps later. I’d like to make > sure the most-commonly-used class has the shortest name. FWIW, there are 440 use of SharedBuffer left vs 422 of ContiguousSharedBuffer :)
Jean-Yves Avenard [:jya]
Comment 45 2021-12-01 04:27:04 PST
Created attachment 445551 [details] Patch for EWS Fix gtk build
Jean-Yves Avenard [:jya]
Comment 46 2021-12-01 04:28:18 PST
Jean-Yves Avenard [:jya]
Comment 47 2021-12-01 04:29:49 PST
Jean-Yves Avenard [:jya]
Comment 48 2021-12-02 04:06:29 PST
Created attachment 445704 [details] Patch rebase
Jean-Yves Avenard [:jya]
Comment 49 2021-12-02 04:18:16 PST
(In reply to Jean-Yves Avenard [:jya] from comment #44) > (In reply to Darin Adler from comment #40) > > I guess we can do the renames as mechanical steps later. I’d like to make > > sure the most-commonly-used class has the shortest name. > > FWIW, there are 440 use of SharedBuffer left vs 422 of > ContiguousSharedBuffer :) Miscalculated: there are 608 ContiguousSharedBuffer in use following this patch, and 1077 SharedBuffer. Not doubt there's much more SharedBuffer that could be made into contiguous ones permanently. But I'm not sure the contiguous SharedBuffer will be the most commonly used.
Jean-Yves Avenard [:jya]
Comment 50 2021-12-03 16:56:00 PST
Created attachment 445918 [details] Patch Simplify ContiguousSharedBuffer::createCFData() on non-Fundation
Jean-Yves Avenard [:jya]
Comment 51 2021-12-03 20:11:41 PST
Created attachment 445948 [details] Patch rebase
Jean-Yves Avenard [:jya]
Comment 52 2021-12-03 22:32:59 PST
Created attachment 445960 [details] Patch fix win crash
Jean-Yves Avenard [:jya]
Comment 53 2021-12-03 23:55:43 PST
Jean-Yves Avenard [:jya]
Comment 54 2021-12-03 23:57:23 PST
Jean-Yves Avenard [:jya]
Comment 55 2021-12-05 21:21:47 PST
Created attachment 445993 [details] Patch Fix SharedBufferPOSIX.cpp, it's not compiled by any of our bots
Darin Adler
Comment 56 2021-12-06 14:32:55 PST
Comment on attachment 445993 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=445993&action=review > Source/WebCore/ChangeLog:32 > + There's a potential increase of temporary memory usage with the > + ScriptBufferSourceProvider class; bug 233511 is tracking it. Presumably this is a small enough amount of additional memory that it’s OK and we don’t have "unshippable" WebKit until it’s done. > Source/WebCore/platform/SharedBuffer.cpp:102 > + if (m_segments.size() == 1) > + return ContiguousSharedBuffer::create(m_segments[0].segment.copyRef()); Isn’t this less efficient than just returning a pointer to the first segment in this case? How common is this likely to be? There’s a new failure mode in the new design where the same shared buffer repeatedly is converted into a ContiguousSharedBuffer. What guarantees that won’t happen. > Source/WebCore/platform/SharedBuffer.cpp:172 > +size_t SharedBuffer::size() const > +{ > + return m_size; > +} > + > +bool SharedBuffer::isEmpty() const > +{ > + return !size(); > +} > + > +bool SharedBuffer::isContiguous() const > +{ > + return m_contiguous; > +} Should any of these go in the header instead as inlines? > Source/WebCore/platform/SharedBuffer.cpp:226 > +void SharedBuffer::append(const char* data, size_t length) > +{ > + append(reinterpret_cast<const uint8_t*>(data), length); > +} Should this go in the header instead as an inline? > Source/WebCore/platform/SharedBuffer.cpp:349 > bool SharedBuffer::hasOneSegment() const > { > - auto it = begin(); > - return it != end() && ++it == end(); > + return m_segments.size() == 1; > } Should this go in the header instead as an inline? > Source/WebCore/platform/SharedBuffer.cpp:412 > +const char* ContiguousSharedBuffer::dataAsCharPtr() const > +{ > + return reinterpret_cast<const char*>(data()); > +} Should this go in the header instead as an inline? > Source/WebCore/platform/SharedBuffer.cpp:544 > +const char* SharedBufferDataView::dataAsCharPtr() const > +{ > + return reinterpret_cast<const char*>(data()); > +} Should this go in the header instead as an inline? > Source/WebCore/platform/SharedBuffer.h:79 > + static Ref<DataSegment> create(Vector<uint8_t>&& data) > + { > + data.shrinkToFit(); > + return adoptRef(*new DataSegment(WTFMove(data))); > + } For future reference/refactoring: Functions like these probably should not be inlined in the header. It makes the code bigger at each call site if there is more than one, and the constructors themselves can often get inlined in these create functions if they are moved out of the header file, even if the constructors aren’t explicitly marked inline. Same for the other create functions. > Source/WebCore/platform/SharedBuffer.h:140 > +#if !USE(FOUNDATION) > + friend class ContiguousSharedBuffer; // For createCFData > +#endif Do we really need the #if here? > Source/WebCore/platform/SharedBuffer.h:281 > + // Ensure that you can't call append on a ContiguousSharedBuffer directly. > + // When called from the base class, it will assert. > + template <typename... Args> > + void append(Args&&...) = delete; Is there an alternate version of this design that doesn’t have the Liskov Substitutability Principle problem? > Source/WebCore/platform/SharedBuffer.h:283 > + WEBCORE_EXPORT const uint8_t *data() const; Misplaced "*" here. > Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:77 > + data = API::Data::createWithoutCopying((const unsigned char*)contiguousBuffer->data(), contiguousBuffer->size(), releaseSharedBuffer, contiguousBuffer.ptr()); This typecast is not needed, that’s already the correct type. > Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp:284 > + RefPtr<ContiguousSharedBuffer> buffer = handle.tryWrapInSharedBuffer(); I suggest auto here. > Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm:569 > + RefPtr<ContiguousSharedBuffer> buffer = frame.editor().dataSelectionForPasteboard(pasteboardType); I suggest auto here. > Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm:-235 > -#if HAVE(UIKIT_WEBKIT_INTERNALS) > - return mode == HTMLMediaElementEnums::VideoFullscreenModeStandard; > -#else > return true; > -#endif This seems like an unrelated change that was included in this patch by accident? > Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm:242 > -#if PLATFORM(IOS_FAMILY) && !HAVE(UIKIT_WEBKIT_INTERNALS) > +#if PLATFORM(IOS_FAMILY) Ditto. > Source/WebKitLegacy/mac/WebView/WebHTMLRepresentation.mm:233 > + auto *parsedArchiveData = [_private->dataSource _documentLoader]->parsedArchiveData(); This should be just auto or auto*, not "auto *". > Source/WebKitLegacy/mac/WebView/WebResource.mm:167 > - NSData *data = nil; > + > + RetainPtr<NSData> data; Good fix! I was prepping for createNSData and spotted this error, and was about to ask you to fix it, but looks like you spotted it too. > Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp:46 > + RefPtr<SharedBuffer> buffer = ContiguousSharedBuffer::createWithContentsOfFile(String("not_existing_file")); Would more auto make these better?
Jean-Yves Avenard [:jya]
Comment 57 2021-12-06 18:57:17 PST
Comment on attachment 445993 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=445993&action=review >> Source/WebCore/ChangeLog:32 >> + ScriptBufferSourceProvider class; bug 233511 is tracking it. > > Presumably this is a small enough amount of additional memory that it’s OK and we don’t have "unshippable" WebKit until it’s done. Here we have a trade-off between speed and memory efficiency. I would need to discuss with others on what we want to achieve here. We could always flatten the buffer before storing it into a ScriptBufferSourceProvider >> Source/WebCore/platform/SharedBuffer.cpp:102 >> + return ContiguousSharedBuffer::create(m_segments[0].segment.copyRef()); > > Isn’t this less efficient than just returning a pointer to the first segment in this case? How common is this likely to be? > > There’s a new failure mode in the new design where the same shared buffer repeatedly is converted into a ContiguousSharedBuffer. What guarantees that won’t happen. > Isn’t this less efficient than just returning a pointer to the first segment in this case? How common is this likely to be? I made the constructor private to keep with the existing style, forcing to go through the create method. I don't see how this would be less efficient, we just explicitly create the object rather than the let the compiler decides what to do. > There’s a new failure mode in the new design where the same shared buffer repeatedly is converted into a ContiguousSharedBuffer In practice it shouldn't happen. A buffer is either flattened when we read its content like when dealing with external framework that requires a pointer and this is done once. Where multiple conversions could occur on the same object, this is where I tracked where the SharedBuffer was first created and made it a ContiguousSharedBuffer instead. There's no guarantee in the future that it won't happen though. However, after bug 233442 and 233677 , I believe the naming gives more visibility of what is happening and how to do the "right thing" will be more obvious to folks. >> Source/WebCore/platform/SharedBuffer.cpp:172 >> +} > > Should any of these go in the header instead as inlines? it's a bit confusing on which is to be made inline vs which one we don't want to. The issue however is with WEBCORE_EXPORT which can't be used on the class if there are inlines. >> Source/WebCore/platform/SharedBuffer.h:79 >> + } > > For future reference/refactoring: > > Functions like these probably should not be inlined in the header. It makes the code bigger at each call site if there is more than one, and the constructors themselves can often get inlined in these create functions if they are moved out of the header file, even if the constructors aren’t explicitly marked inline. > > Same for the other create functions. I'll move those to the code then. >> Source/WebCore/platform/SharedBuffer.h:140 >> +#endif > > Do we really need the #if here? no. but it's the only place it's needed. I'll remove it. >> Source/WebCore/platform/SharedBuffer.h:281 >> + void append(Args&&...) = delete; > > Is there an alternate version of this design that doesn’t have the Liskov Substitutability Principle problem? This pattern disappear following bug 233442, append no longer exists. This was primarily used as a WIP where most SharedBuffer instances where converted to ContiguousSharedBuffer and could tell at compile time where it was misused. Easier to spot than waiting on an assertion during a test. >> Source/WebKit/WebProcess/cocoa/VideoFullscreenManager.mm:-235 >> -#endif > > This seems like an unrelated change that was included in this patch by accident? oops.
Jean-Yves Avenard [:jya]
Comment 58 2021-12-06 18:59:08 PST
Comment on attachment 445993 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=445993&action=review >> Tools/TestWebKitAPI/Tests/WebCore/SharedBuffer.cpp:46 >> + RefPtr<SharedBuffer> buffer = ContiguousSharedBuffer::createWithContentsOfFile(String("not_existing_file")); > > Would more auto make these better? probably, I mostly kept the existing code as-is.
Jean-Yves Avenard [:jya]
Comment 59 2021-12-06 21:44:09 PST
Created attachment 446118 [details] Patch apply comments
Jean-Yves Avenard [:jya]
Comment 60 2021-12-06 22:24:41 PST
Created attachment 446125 [details] Patch apply comments
Jean-Yves Avenard [:jya]
Comment 61 2021-12-06 23:08:40 PST
Created attachment 446127 [details] Patch pick some fly-by fixes from bug 233442 requires for this patch to not cause regressions
Jean-Yves Avenard [:jya]
Comment 62 2021-12-09 05:17:57 PST
Created attachment 446525 [details] Patch Rebase
Jean-Yves Avenard [:jya]
Comment 63 2021-12-09 05:46:01 PST
Created attachment 446529 [details] Patch Fix compilation error following rebase
Jean-Yves Avenard [:jya]
Comment 64 2021-12-10 14:19:51 PST
Created attachment 446812 [details] Patch rebase
Jean-Yves Avenard [:jya]
Comment 65 2021-12-11 03:58:32 PST
Created attachment 446870 [details] Patch Rebase, convert new code to ContiguousSharedBuffer
Jean-Yves Avenard [:jya]
Comment 66 2021-12-11 05:12:04 PST
Created attachment 446874 [details] Patch Fix compilation on iOS, GTK and Windows
Jean-Yves Avenard [:jya]
Comment 67 2021-12-11 05:40:01 PST
Jean-Yves Avenard [:jya]
Comment 68 2021-12-12 03:50:13 PST
Created attachment 446929 [details] Patch Yet another rebase
Jean-Yves Avenard [:jya]
Comment 69 2021-12-12 21:54:47 PST
Created attachment 446966 [details] Patch Fix intermittent crash
EWS
Comment 70 2021-12-13 00:31:42 PST
Committed r286937 (245163@main): <https://commits.webkit.org/245163@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 446966 [details].
Fujii Hironori
Comment 71 2022-05-30 15:03:37 PDT
Filed: Bug 241110 – REGRESSION(245163@main) Can't load a very large image as an image document
Note You need to log in before you can comment on or make changes to this bug.