Commit dc224d28 authored by Kouhei Ueno's avatar Kouhei Ueno Committed by Commit Bot

BackgroundHTMLParser: Make token limits unconfigurable

I couldn't find any occurrence in tests that attempt to dynamically reconfigure this.
This CL just makes them use constants to reduce complexity.

Bug: 689702
Change-Id: I431aaec674a439d82499a1b4099d4de64e75f5c1
Reviewed-on: https://chromium-review.googlesource.com/1032313
Commit-Queue: Kouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554343}
parent d55f459e
......@@ -530,19 +530,6 @@
type: "ImageAnimationPolicy",
},
// Number of outstanding and pending tokens allowed in the background HTML
// parser. A value of 0 indicates the parser should use its default value.
{
name: "backgroundHtmlParserOutstandingTokenLimit",
initial: 0,
type: "unsigned",
},
{
name: "backgroundHtmlParserPendingTokenLimit",
initial: 0,
type: "unsigned",
},
// Html preload scanning is a fast, early scan of HTML documents to find loadable
// resources before the parser advances to them. If it is disabled, resources will
// be loaded later.
......
......@@ -50,19 +50,21 @@ namespace blink {
// potentially time if the speculation fails). So we limit our outstanding
// tokens arbitrarily to 10,000. Our maximal memory spent speculating will be
// approximately:
// (defaultOutstandingTokenLimit + defaultPendingTokenLimit) *
// sizeof(CompactToken)
// (kOutstandingTokenLimit + kPendingTokenLimit) * sizeof(CompactToken)
//
// We use a separate low and high water mark to avoid
// constantly topping off the main thread's token buffer. At time of writing,
// this is (10000 + 1000) * 28 bytes = ~308kb of memory. These numbers have not
// been tuned.
static const size_t kDefaultOutstandingTokenLimit = 10000;
static const size_t kOutstandingTokenLimit = 10000;
// We limit our chucks to 1000 tokens, to make sure the main thread is never
// waiting on the parser thread for tokens. This was tuned in
// https://bugs.webkit.org/show_bug.cgi?id=110408.
static const size_t kDefaultPendingTokenLimit = 1000;
static const size_t kPendingTokenLimit = 1000;
static_assert(kOutstandingTokenLimit > kPendingTokenLimit,
"Outstanding token limit is applied after pending token limit.");
using namespace HTMLNames;
......@@ -106,9 +108,7 @@ void BackgroundHTMLParser::Init(
TokenPreloadScanner::ScannerType::kMainDocument));
}
BackgroundHTMLParser::Configuration::Configuration()
: outstanding_token_limit(kDefaultOutstandingTokenLimit),
pending_token_limit(kDefaultPendingTokenLimit) {}
BackgroundHTMLParser::Configuration::Configuration() {}
BackgroundHTMLParser::BackgroundHTMLParser(
std::unique_ptr<Configuration> config,
......@@ -117,9 +117,7 @@ BackgroundHTMLParser::BackgroundHTMLParser(
tokenizer_(HTMLTokenizer::Create(config->options)),
tree_builder_simulator_(config->options),
options_(config->options),
outstanding_token_limit_(config->outstanding_token_limit),
parser_(config->parser),
pending_token_limit_(config->pending_token_limit),
xss_auditor_(std::move(config->xss_auditor)),
decoder_(std::move(config->decoder)),
loading_task_runner_(std::move(loading_task_runner)),
......@@ -127,9 +125,6 @@ BackgroundHTMLParser::BackgroundHTMLParser(
HTMLDocumentParser::TokenizedChunk::kNoPendingToken),
starting_script_(false),
weak_factory_(this) {
DCHECK_GT(outstanding_token_limit_, 0u);
DCHECK_GT(pending_token_limit_, 0u);
DCHECK_GE(outstanding_token_limit_, pending_token_limit_);
}
BackgroundHTMLParser::~BackgroundHTMLParser() = default;
......@@ -223,7 +218,7 @@ void BackgroundHTMLParser::PumpTokenizer() {
HTMLTreeBuilderSimulator::kOtherToken;
// No need to start speculating until the main thread has almost caught up.
if (input_.TotalCheckpointTokenCount() > outstanding_token_limit_)
if (input_.TotalCheckpointTokenCount() > kOutstandingTokenLimit)
return;
while (true) {
......@@ -277,12 +272,12 @@ void BackgroundHTMLParser::PumpTokenizer() {
if (simulated_token == HTMLTreeBuilderSimulator::kScriptEnd ||
simulated_token == HTMLTreeBuilderSimulator::kStyleEnd ||
simulated_token == HTMLTreeBuilderSimulator::kLink ||
pending_tokens_.size() >= pending_token_limit_) {
pending_tokens_.size() >= kPendingTokenLimit) {
EnqueueTokenizedChunk();
// If we're far ahead of the main thread, yield for a bit to avoid
// consuming too much memory.
if (input_.TotalCheckpointTokenCount() > outstanding_token_limit_)
if (input_.TotalCheckpointTokenCount() > kOutstandingTokenLimit)
break;
}
}
......
......@@ -59,10 +59,6 @@ class BackgroundHTMLParser {
base::WeakPtr<HTMLDocumentParser> parser;
std::unique_ptr<XSSAuditor> xss_auditor;
std::unique_ptr<TextResourceDecoder> decoder;
// outstandingTokenLimit must be greater than or equal to
// pendingTokenLimit
size_t outstanding_token_limit;
size_t pending_token_limit;
};
// The returned BackgroundHTMLParser should only be used on the parser
......@@ -119,11 +115,9 @@ class BackgroundHTMLParser {
std::unique_ptr<HTMLTokenizer> tokenizer_;
HTMLTreeBuilderSimulator tree_builder_simulator_;
HTMLParserOptions options_;
const size_t outstanding_token_limit_;
base::WeakPtr<HTMLDocumentParser> parser_;
CompactHTMLTokenStream pending_tokens_;
const size_t pending_token_limit_;
PreloadRequestStream pending_preloads_;
ViewportDescriptionWrapper viewport_description_;
XSSInfoStream pending_xss_infos_;
......
......@@ -37,7 +37,6 @@
#include "third_party/blink/renderer/core/dom/document_fragment.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/html/html_document.h"
#include "third_party/blink/renderer/core/html/parser/atomic_html_token.h"
#include "third_party/blink/renderer/core/html/parser/background_html_parser.h"
......@@ -803,24 +802,6 @@ void HTMLDocumentParser::StartBackgroundParser() {
config->xss_auditor->Init(GetDocument(), &xss_auditor_delegate_);
config->decoder = TakeDecoder();
if (GetDocument()->GetSettings()) {
if (GetDocument()
->GetSettings()
->GetBackgroundHtmlParserOutstandingTokenLimit()) {
config->outstanding_token_limit =
GetDocument()
->GetSettings()
->GetBackgroundHtmlParserOutstandingTokenLimit();
}
if (GetDocument()
->GetSettings()
->GetBackgroundHtmlParserPendingTokenLimit()) {
config->pending_token_limit =
GetDocument()
->GetSettings()
->GetBackgroundHtmlParserPendingTokenLimit();
}
}
DCHECK(config->xss_auditor->IsSafeToSendToAnotherThread());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment