Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge r174190 - Add basic caching for Document.cookie API
https://bugs.webkit.org/show_bug.cgi?id=137225 Reviewed by Alexey Proskuryakov. Source/WebCore: While profiling the load of nytimes.com, I noticed that the site is accessing ~250 times document.cookie, just during page load. Accessing document.cookie is currently slow because we: - Call WebPlatformStrategies::cookiesForDOM() virtual function - Send a sync IPC message to the Network process to retrieve the cookies - The Network process gets the list of cookies from CFNetwork then serializes the result to send it back to the WebProcess - We unserialize the cookies into an NSList of cookies - We filter-out the cookies that are 'httpOnly' and construct a new NSList of cookies - We create a WTF String out of the cookies NSList In the case of nytimes.com, it turns out that up to 100 calls to document.cookie() are made in the same event loop iteration. This patch thus caches / freezes the cookies until we return to the event loop so that consecutive calls to document.cookie() are extremely fast. Doing so seems to be sufficient to achieve a ~87% cache hit for nytimes.com page load. The cookies cache is invalidated whenever: - document.cookie is set - we return to the event loop - a network resource is loaded synchronously as it may cause cookies to be set before we return to the event loop Test: http/tests/cookies/sync-xhr-set-cookie-invalidates-cache.html * dom/Document.cpp: (WebCore::Document::Document): (WebCore::Document::open): (WebCore::Document::cookie): (WebCore::Document::setCookie): (WebCore::Document::setCookieURL): (WebCore::Document::initSecurityContext): (WebCore::Document::setDOMCookieCache): (WebCore::Document::invalidateDOMCookieCache): (WebCore::Document::domCookieCacheExpiryTimerFired): (WebCore::Document::didLoadResourceSynchronously): * dom/Document.h: (WebCore::Document::domCookieCache): (WebCore::Document::isDOMCookieCacheValid): (WebCore::Document::setCookieURL): Deleted. * dom/ScriptExecutionContext.cpp: (WebCore::ScriptExecutionContext::didLoadResourceSynchronously): * dom/ScriptExecutionContext.h: * loader/ThreadableLoader.cpp: (WebCore::ThreadableLoader::loadResourceSynchronously): LayoutTests: Add a layout test to make sure that document.cookie returns updated results after cookies are set via a sync XHR. * http/tests/cookies/sync-xhr-set-cookie-invalidates-cache-expected.txt: Added. * http/tests/cookies/sync-xhr-set-cookie-invalidates-cache.html: Added. Canonical link: https://commits.webkit.org/154760.64@webkitgtk/2.6 git-svn-id: https://svn.webkit.org/repository/webkit/releases/WebKitGTK/webkit-2.6@174454 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
1 parent
b458b1b
commit 6e5cb9e
Showing
10 changed files
with
176 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
LayoutTests/http/tests/cookies/sync-xhr-set-cookie-invalidates-cache-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Tests that document.cookie returns the right value after a sync XHR | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS normalizeCookie(document.cookie) is "testKey=testValue" | ||
PASS xhr.status is 200 | ||
PASS normalizeCookie(document.cookie) is "testKey=testValue; xhrKey=xhrValue" | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
22 changes: 22 additions & 0 deletions
22
LayoutTests/http/tests/cookies/sync-xhr-set-cookie-invalidates-cache.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<script src='resources/cookies-test-pre.js'></script> | ||
|
||
<script> | ||
description('Tests that document.cookie returns the right value after a sync XHR'); | ||
|
||
document.cookie = "testKey=testValue"; | ||
shouldBeEqualToString('normalizeCookie(document.cookie)', 'testKey=testValue'); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', 'resources/setCookies.cgi', false); | ||
var cookie = 'xhrKey=xhrValue; path=/'; | ||
xhr.setRequestHeader('SET-COOKIE', cookie); | ||
xhr.send(); | ||
|
||
// This is so the cookie gets removed at the end of the test. | ||
registerCookieForCleanup(cookie); | ||
|
||
shouldBe('xhr.status', '200'); | ||
shouldBeEqualToString('normalizeCookie(document.cookie)', 'testKey=testValue; xhrKey=xhrValue'); | ||
|
||
</script> | ||
<script src='resources/cookies-test-post.js'></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters