Bug 264971 - ScriptBuffer append with empty string adds empty segment
Summary: ScriptBuffer append with empty string adds empty segment
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Lam
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-11-16 11:58 PST by Cristian Linte
Modified: 2023-11-29 07:03 PST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.