Bug 264971

Summary: ScriptBuffer append with empty string adds empty segment
Product: WebKit Reporter: Cristian Linte <ioancris>
Component: WebCore JavaScriptAssignee: Mark Lam <mark.lam>
Status: RESOLVED FIXED    
Severity: Normal CC: jean-yves.avenard, mark.lam, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   

Description Cristian Linte 2023-11-16 11:58:59 PST
ScriptBufferSourceProvider sometimes receives a ScriptBuffer with 2 data segments where 2nd segment is empty (size 0, buffer null). The 2nd empty segment was likely added in WorkerScriptLoader::didFinishLoading by append(decoder->flush()) where flush can return an empty string.
ScriptBufferSourceProvider will call makeContiguous on scriptBuffer which for the above case end up making an unnecessary copy and this memory is kept alive by ScriptBufferSourceProvider thus increasing memory usage.

ScriptBuffer should not add an empty segment to the buffer when append is called with empty string.
Comment 1 Radar WebKit Bug Importer 2023-11-23 11:59:14 PST
<rdar://problem/118752844>
Comment 2 Mark Lam 2023-11-23 13:32:15 PST
Pull request: https://github.com/WebKit/WebKit/pull/20855
Comment 3 EWS 2023-11-29 07:03:26 PST
Committed 271275@main (d445ae96c998): <https://commits.webkit.org/271275@main>

Reviewed commits have been landed. Closing PR #20855 and removing active labels.