Chromium Code Reviews| 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..3ab5960f8c78a891951e86cc641d67e55908ef19 100644 |
| --- a/Source/core/html/parser/BackgroundHTMLParser.cpp |
| +++ b/Source/core/html/parser/BackgroundHTMLParser.cpp |
| @@ -36,6 +36,8 @@ |
| #include "public/platform/WebScheduler.h" |
| #include "wtf/text/TextPosition.h" |
| +#include <algorithm> |
| + |
| namespace blink { |
| // On a network with high latency and high bandwidth, using a device |
| @@ -44,17 +46,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 +89,30 @@ 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(std::max(config->outstandingTokenLimit, config->pendingTokenLimit)) |
|
Nate Chapin
2015/06/11 18:48:23
Why take the max of the two here? Should we assert
Bryan McQuade
2015/06/12 14:12:59
Yes, that's clearer. Agree. I've made this change.
|
| , 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); |
| } |
| BackgroundHTMLParser::~BackgroundHTMLParser() |
| @@ -205,7 +218,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 +255,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; |
| } |
| } |