Changeset 145277 in webkit
- Timestamp:
- Mar 8, 2013 3:39:25 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r145276 r145277 1 2013-03-08 Eric Seidel <eric@webkit.org> 2 3 Free up background parser's checkpoints when speculation succeeds 4 https://bugs.webkit.org/show_bug.cgi?id=110547 5 6 Reviewed by Adam Barth. 7 8 This should be a memory (and possible perf) win while parsing 9 pages, as we will no longer hold multiple copies of every 10 source byte during the whole parse. 11 12 Many LayoutTests exercise this code path, and I've manually (debugger and printf) 13 that we're hitting this code, but we'll have to wait for the memory/perf bots 14 to tell us if this shows up as a win. 15 16 We only bother to message the parser at the end of a speculation chain, so as not 17 to send too many messages to the background parser. 18 19 * html/parser/BackgroundHTMLInputStream.cpp: 20 (WebCore::BackgroundHTMLInputStream::BackgroundHTMLInputStream): 21 (WebCore::BackgroundHTMLInputStream::invalidateCheckpointsUpThrough): 22 (WebCore): 23 (WebCore::BackgroundHTMLInputStream::rewindTo): 24 * html/parser/BackgroundHTMLInputStream.h: 25 (BackgroundHTMLInputStream): 26 (Checkpoint): 27 (WebCore::BackgroundHTMLInputStream::Checkpoint::isNull): 28 (WebCore::BackgroundHTMLInputStream::Checkpoint::clear): 29 * html/parser/BackgroundHTMLParser.cpp: 30 (WebCore::BackgroundHTMLParser::passedCheckpoint): 31 (WebCore): 32 * html/parser/BackgroundHTMLParser.h: 33 (BackgroundHTMLParser): 34 * html/parser/HTMLDocumentParser.cpp: 35 (WebCore::HTMLDocumentParser::pumpPendingSpeculations): 36 1 37 2013-03-08 Chandra Shekar Vallala <brk376@motorola.com> 2 38 -
trunk/Source/WebCore/html/parser/BackgroundHTMLInputStream.cpp
r144714 r145277 33 33 34 34 BackgroundHTMLInputStream::BackgroundHTMLInputStream() 35 : m_firstValidCheckpointIndex(0) 36 , m_firstValidSegmentIndex(0) 35 37 { 36 38 } … … 54 56 } 55 57 58 void BackgroundHTMLInputStream::invalidateCheckpointsUpThrough(HTMLInputCheckpoint checkpointIndex) 59 { 60 ASSERT(checkpointIndex < m_checkpoints.size()); 61 ASSERT(checkpointIndex >= m_firstValidCheckpointIndex); 62 const Checkpoint& checkpoint = m_checkpoints[checkpointIndex]; 63 ASSERT(m_firstValidSegmentIndex <= checkpoint.numberOfSegmentsAlreadyAppended); 64 for (size_t i = m_firstValidSegmentIndex; i < checkpoint.numberOfSegmentsAlreadyAppended; ++i) 65 m_segments[i] = String(); 66 m_firstValidSegmentIndex = checkpoint.numberOfSegmentsAlreadyAppended; 67 68 for (size_t i = m_firstValidCheckpointIndex; i <= checkpointIndex; ++i) 69 m_checkpoints[i].clear(); 70 m_firstValidCheckpointIndex = checkpointIndex + 1; 71 } 72 56 73 void BackgroundHTMLInputStream::rewindTo(HTMLInputCheckpoint checkpointIndex, const String& unparsedInput) 57 74 { 58 75 ASSERT(checkpointIndex < m_checkpoints.size()); // If this ASSERT fires, checkpointIndex is invalid. 59 76 const Checkpoint& checkpoint = m_checkpoints[checkpointIndex]; 77 ASSERT(!checkpoint.isNull()); 60 78 61 79 bool isClosed = m_current.isClosed(); … … 63 81 m_current = checkpoint.input; 64 82 65 for (size_t i = checkpoint.numberOfSegmentsAlreadyAppended; i < m_segments.size(); ++i) 83 for (size_t i = checkpoint.numberOfSegmentsAlreadyAppended; i < m_segments.size(); ++i) { 84 ASSERT(!m_segments[i].isNull()); 66 85 m_current.append(SegmentedString(m_segments[i])); 86 } 67 87 68 88 if (!unparsedInput.isEmpty()) … … 76 96 m_segments.clear(); 77 97 m_checkpoints.clear(); 98 m_firstValidCheckpointIndex = 0; 99 m_firstValidSegmentIndex = 0; 78 100 } 79 101 -
trunk/Source/WebCore/html/parser/BackgroundHTMLInputStream.h
r142673 r145277 51 51 HTMLInputCheckpoint createCheckpoint(); 52 52 void rewindTo(HTMLInputCheckpoint, const String& unparsedInput); 53 void invalidateCheckpointsUpThrough(HTMLInputCheckpoint); 53 54 54 55 private: … … 58 59 SegmentedString input; 59 60 size_t numberOfSegmentsAlreadyAppended; 61 62 #ifndef NDEBUG 63 bool isNull() const { return input.isEmpty() && !numberOfSegmentsAlreadyAppended; } 64 #endif 65 void clear() { input.clear(); numberOfSegmentsAlreadyAppended = 0; } 60 66 }; 61 67 … … 63 69 Vector<String> m_segments; 64 70 Vector<Checkpoint> m_checkpoints; 71 72 // Note: These indicies may === vector.size(), in which case there are no valid checkpoints/segments at this time. 73 size_t m_firstValidCheckpointIndex; 74 size_t m_firstValidSegmentIndex; 65 75 }; 66 76 -
trunk/Source/WebCore/html/parser/BackgroundHTMLParser.cpp
r144801 r145277 168 168 } 169 169 170 void BackgroundHTMLParser::passedCheckpoint(HTMLInputCheckpoint inputCheckpoint) 171 { 172 // Note, we should not have to worry about the index being invalid 173 // as messages from the main thread will be processed in FIFO order. 174 m_input.invalidateCheckpointsUpThrough(inputCheckpoint); 175 } 176 170 177 void BackgroundHTMLParser::finish() 171 178 { -
trunk/Source/WebCore/html/parser/BackgroundHTMLParser.h
r144801 r145277 75 75 void append(const String&); 76 76 void resumeFrom(PassOwnPtr<Checkpoint>); 77 void passedCheckpoint(HTMLInputCheckpoint); 77 78 void finish(); 78 79 void stop(); -
trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp
r145248 r145277 458 458 459 459 double startTime = currentTime(); 460 HTMLInputCheckpoint lastCheckpointPassed = 0; 460 461 461 462 while (!m_speculations.isEmpty()) { 462 processParsedChunkFromBackgroundParser(m_speculations.takeFirst()); 463 464 if (isWaitingForScripts() || isStopped()) 463 OwnPtr<ParsedChunk> chunk = m_speculations.takeFirst(); 464 lastCheckpointPassed = chunk->inputCheckpoint; 465 processParsedChunkFromBackgroundParser(chunk.release()); 466 467 // Processing a chunk can call document.write, causing us to invalidate any remaining speculations. 468 if (m_speculations.isEmpty() || isStopped()) { 469 // We're aborting these speculations, so don't tell the parser we've passed a checkpoint (its already cleared its checkpoints). 470 lastCheckpointPassed = 0; 465 471 break; 466 467 if (currentTime() - startTime > parserTimeLimit && !m_speculations.isEmpty()) { 472 } 473 474 if (isWaitingForScripts()) 475 break; 476 477 if (currentTime() - startTime > parserTimeLimit) { 468 478 m_parserScheduler->scheduleForResume(); 469 479 break; 470 480 } 471 481 } 482 483 if (lastCheckpointPassed) 484 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::passedCheckpoint, m_backgroundParser, lastCheckpointPassed)); 472 485 473 486 InspectorInstrumentation::didWriteHTML(cookie, lineNumber().zeroBasedInt());
Note: See TracChangeset
for help on using the changeset viewer.