haikuwebkit/Source/WebCore/loader/LoadSchedulingMode.h

48 lines
1.8 KiB
C
Raw Permalink Normal View History

Implement visibility based resource load scheduling for low priority resources https://bugs.webkit.org/show_bug.cgi?id=220728 Reviewed by Geoff Garen. Source/WebCore: Track load scheduling mode during on per page basis. Add support for prioritizing resources based on their visibility. * Headers.cmake: * WebCore.xcodeproj/project.pbxproj: * loader/LoaderStrategy.cpp: (WebCore::LoaderStrategy::setResourceLoadSchedulingMode): (WebCore::LoaderStrategy::prioritizeResourceLoads): * loader/LoaderStrategy.h: * page/Page.cpp: (WebCore::Page::didStartProvisionalLoad): (WebCore::Page::didFinishLoad): Sheduled modes is is disabled at latest when the load completes. (WebCore::Page::doAfterUpdateRendering): (WebCore::Page::prioritizeVisibleResources): After rendering update, if in scheduled mode, check the visibility status of images resources. Prioritize loads for visible resources. Move out of the shceduled mode if the document is fully parsed and all visibile loads are completed. (WebCore::Page::setLoadSchedulingMode): * page/Page.h: (WebCore::Page::loadSchedulingMode const): Source/WebKit: Add a simple network process side resource load scheduler. When active it limits the number of low priority resource loads (mostly images) that are passed to network layer. The current limit is 6 per host, reduced by any ongoing higher priority loads. This reduces impact of low priority loads to higher priority ones, espcially on HTTP/2. The scheduler also supports reprioritizing loads. This is used to let images currently in the viewport to skip the queue and start their loads faster. The feature is not enabled in this patch. * NetworkProcess/Downloads/Download.cpp: (WebKit::Download::cancel): (WebKit::Download::didReceiveData): (WebKit::Download::didFinish): (WebKit::Download::didFail): * NetworkProcess/NetworkConnectionToWebProcess.cpp: (WebKit::NetworkConnectionToWebProcess::clearPageSpecificData): (WebKit::NetworkConnectionToWebProcess::removeStorageAccessForFrame): (WebKit::NetworkConnectionToWebProcess::setResourceLoadSchedulingMode): (WebKit::NetworkConnectionToWebProcess::prioritizeResourceLoads): (WebKit::NetworkConnectionToWebProcess::clearPageSpecificDataForResourceLoadStatistics): Deleted. Rename to clearPageSpecificData and move out of #if. * NetworkProcess/NetworkConnectionToWebProcess.h: * NetworkProcess/NetworkConnectionToWebProcess.messages.in: * NetworkProcess/NetworkLoad.cpp: (WebKit::NetworkLoad::start): (WebKit::NetworkLoad::startWithScheduling): (WebKit::NetworkLoad::~NetworkLoad): (WebKit::NetworkLoad::didCompleteWithError): * NetworkProcess/NetworkLoad.h: * NetworkProcess/NetworkLoadScheduler.cpp: Added. (WebKit::NetworkLoadScheduler::HostContext::schedule): (WebKit::NetworkLoadScheduler::HostContext::unschedule): (WebKit::NetworkLoadScheduler::HostContext::prioritize): (WebKit::NetworkLoadScheduler::HostContext::start): (WebKit::NetworkLoadScheduler::HostContext::~HostContext): (WebKit::NetworkLoadScheduler::schedule): (WebKit::NetworkLoadScheduler::unschedule): (WebKit::NetworkLoadScheduler::setResourceLoadSchedulingMode): (WebKit::NetworkLoadScheduler::prioritizeLoads): (WebKit::NetworkLoadScheduler::clearPageData): (WebKit::NetworkLoadScheduler::contextForLoad): * NetworkProcess/NetworkLoadScheduler.h: Copied from Source/WebCore/loader/LoaderStrategy.cpp. * NetworkProcess/NetworkResourceLoader.cpp: (WebKit::NetworkResourceLoader::startNetworkLoad): * NetworkProcess/NetworkSession.cpp: (WebKit::NetworkSession::networkLoadScheduler): * NetworkProcess/NetworkSession.h: * NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp: (WebKit::NetworkCache::SpeculativeLoad::SpeculativeLoad): * Sources.txt: * WebKit.xcodeproj/project.pbxproj: * WebProcess/Network/WebLoaderStrategy.cpp: (WebKit::WebLoaderStrategy::setResourceLoadSchedulingMode): (WebKit::WebLoaderStrategy::prioritizeResourceLoads): * WebProcess/Network/WebLoaderStrategy.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::close): Source/WTF: * Scripts/Preferences/WebPreferencesInternal.yaml: Add an internal setting, default to off for now. Canonical link: https://commits.webkit.org/233392@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271946 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-01-27 12:39:27 +00:00
/*
* Copyright (C) 2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <wtf/EnumTraits.h>
namespace WebCore {
enum class LoadSchedulingMode : uint8_t {
Direct, // All loads are issued directly to network layer.
Prioritized // Low priority loads may get delayed in favor of higher priority ones.
};
}
namespace WTF {
template<> struct EnumTraits<WebCore::LoadSchedulingMode> {
using values = EnumValues<
WebCore::LoadSchedulingMode,
WebCore::LoadSchedulingMode::Direct,
WebCore::LoadSchedulingMode::Prioritized
>;
};
}