Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: f35ee5f5a5af539cf2343ea3ad9b5b4c3f7dcba4
      
https://github.com/WebKit/WebKit/commit/f35ee5f5a5af539cf2343ea3ad9b5b4c3f7dcba4
  Author: Ben Nham <[email protected]>
  Date:   2025-12-12 (Fri, 12 Dec 2025)

  Changed paths:
    M Source/WebKit/Platform/IPC/TransferString.h
    A Source/WebKit/Platform/IPC/cocoa/TransferStringCocoa.mm
    M Source/WebKit/Platform/SourcesCocoa.txt
    M Source/WebKit/Platform/cocoa/NetworkIssueReporter.h
    M Source/WebKit/Platform/cocoa/NetworkIssueReporter.mm
    M Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
    M Source/WebKit/WebKit.xcodeproj/project.pbxproj
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm

  Log Message:
  -----------
  Reduce number of memory copies needed to evaluate long JS strings
https://bugs.webkit.org/show_bug.cgi?id=304037
rdar://166338115

Reviewed by Alex Christensen.

This has the same goal as 304155@main, which is to reduce the number of string 
copies associated
with large JS scripts that are repeatedly evaluated in to multiple frames or 
web views.

This builds on the existing TransferString work (303899@main) and adds a new 
method
`TransferString::createCached(NSString *)`. This method will either create a 
new TransferString
instance associated with the NSString (and then cache it using an Obj-C 
associated object), or reuse
an existing TransferString. By reusing the cached TransferString, we end up 
reusing the same shared
memory mapping for that string's bytes across multiple evaluateJavaScript 
invocations and across
multiple processes.

For now, this optimization is only enabled on the autofill world, since we know 
this optimization is
profitable in that world. It might not be profitable to do this caching in 
other worlds (e.g. some
use cases might evaluate lots of large transient script strings). This seems 
fine for now until we
can develop a better heuristic around when it is profitable to cache the memory 
mapping.

Finally, reduce `transferAsMappingSize` to a single page so that this 
optimization applies to more
strings. On the receiving end (in `WebPage::runJavaScript`), the call to 
`TransferString::release`
uses `transferAsMappingSize` as a hint for whether to reuse the virtual copy or 
to create a new
physical copy of the bytes. Reduce this to a single page to maximize memory 
savings.

Test: Tools/TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm
* Source/WebKit/Platform/IPC/TransferString.h:
* Source/WebKit/Platform/IPC/cocoa/TransferStringCocoa.mm: Added.
(-[_WKTransferStringWrapper initWithString:]):
(-[_WKTransferStringWrapper string]):
(IPC::TransferString::createCached):
* Source/WebKit/Platform/SourcesCocoa.txt:
* Source/WebKit/Platform/cocoa/NetworkIssueReporter.h:
* Source/WebKit/Platform/cocoa/NetworkIssueReporter.mm:
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView 
_evaluateJavaScript:asAsyncFunction:withSourceURL:withArguments:forceUserGesture:inFrame:inWorld:completionHandler:]):
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm:
(TEST(WKUserContentController, EvaluateLargeJavaScriptStringInAutoFillWorld)):

Canonical link: https://commits.webkit.org/304383@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to