| Index: Source/core/html/parser/BackgroundHTMLParser.cpp
|
| diff --git a/Source/core/html/parser/BackgroundHTMLParser.cpp b/Source/core/html/parser/BackgroundHTMLParser.cpp
|
| index 1210ace18d02a201d45fea4ca3d45e48ad43f617..fc06a4cffd0011d8795204cfc41633d952a0605b 100644
|
| --- a/Source/core/html/parser/BackgroundHTMLParser.cpp
|
| +++ b/Source/core/html/parser/BackgroundHTMLParser.cpp
|
| @@ -44,17 +44,18 @@ namespace blink {
|
| // This is a waste of memory (and potentially time if the speculation fails).
|
| // So we limit our outstanding tokens arbitrarily to 10,000.
|
| // Our maximal memory spent speculating will be approximately:
|
| -// (outstandingTokenLimit + pendingTokenLimit) * sizeof(CompactToken)
|
| +// (defaultOutstandingTokenLimit + defaultPendingTokenLimit) *
|
| +// 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 outstandingTokenLimit = 10000;
|
| +static const size_t defaultOutstandingTokenLimit = 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 pendingTokenLimit = 1000;
|
| +static const size_t defaultPendingTokenLimit = 1000;
|
|
|
| using namespace HTMLNames;
|
|
|
| @@ -86,20 +87,31 @@ void BackgroundHTMLParser::start(PassRefPtr<WeakReference<BackgroundHTMLParser>>
|
| // Caller must free by calling stop().
|
| }
|
|
|
| +BackgroundHTMLParser::Configuration::Configuration()
|
| + : outstandingTokenLimit(defaultOutstandingTokenLimit)
|
| + , pendingTokenLimit(defaultPendingTokenLimit)
|
| +{
|
| +}
|
| +
|
| BackgroundHTMLParser::BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHTMLParser>> reference, PassOwnPtr<Configuration> config, WebScheduler* scheduler)
|
| : m_weakFactory(reference, this)
|
| , m_token(adoptPtr(new HTMLToken))
|
| , m_tokenizer(HTMLTokenizer::create(config->options))
|
| , m_treeBuilderSimulator(config->options)
|
| , m_options(config->options)
|
| + , m_outstandingTokenLimit(config->outstandingTokenLimit)
|
| , m_parser(config->parser)
|
| , m_pendingTokens(adoptPtr(new CompactHTMLTokenStream))
|
| + , m_pendingTokenLimit(config->pendingTokenLimit)
|
| , m_xssAuditor(config->xssAuditor.release())
|
| , m_preloadScanner(config->preloadScanner.release())
|
| , m_decoder(config->decoder.release())
|
| , m_scheduler(scheduler)
|
| , m_startingScript(false)
|
| {
|
| + ASSERT(m_outstandingTokenLimit > 0);
|
| + ASSERT(m_pendingTokenLimit > 0);
|
| + ASSERT(m_outstandingTokenLimit >= m_pendingTokenLimit);
|
| }
|
|
|
| BackgroundHTMLParser::~BackgroundHTMLParser()
|
| @@ -205,7 +217,7 @@ void BackgroundHTMLParser::pumpTokenizer()
|
| HTMLTreeBuilderSimulator::SimulatedToken simulatedToken = HTMLTreeBuilderSimulator::OtherToken;
|
|
|
| // No need to start speculating until the main thread has almost caught up.
|
| - if (m_input.totalCheckpointTokenCount() > outstandingTokenLimit)
|
| + if (m_input.totalCheckpointTokenCount() > m_outstandingTokenLimit)
|
| return;
|
|
|
| while (true) {
|
| @@ -242,10 +254,10 @@ void BackgroundHTMLParser::pumpTokenizer()
|
|
|
| m_token->clear();
|
|
|
| - if (simulatedToken == HTMLTreeBuilderSimulator::ScriptEnd || m_pendingTokens->size() >= pendingTokenLimit) {
|
| + if (simulatedToken == HTMLTreeBuilderSimulator::ScriptEnd || m_pendingTokens->size() >= m_pendingTokenLimit) {
|
| sendTokensToMainThread();
|
| // If we're far ahead of the main thread, yield for a bit to avoid consuming too much memory.
|
| - if (m_input.totalCheckpointTokenCount() > outstandingTokenLimit)
|
| + if (m_input.totalCheckpointTokenCount() > m_outstandingTokenLimit)
|
| break;
|
| }
|
| }
|
|
|