| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 if (Platform::current() | 106 if (Platform::current() |
| 107 ->currentThread() | 107 ->currentThread() |
| 108 ->scheduler() | 108 ->scheduler() |
| 109 ->shouldYieldForHighPriorityWork()) | 109 ->shouldYieldForHighPriorityWork()) |
| 110 return true; | 110 return true; |
| 111 | 111 |
| 112 const double parserTimeLimit = 0.5; | 112 const double parserTimeLimit = 0.5; |
| 113 if (session.elapsedTime() > parserTimeLimit) | 113 if (session.elapsedTime() > parserTimeLimit) |
| 114 return true; | 114 return true; |
| 115 | 115 |
| 116 // Yield if a lot of DOM work has been done in this session and a script tag i
s | 116 // Yield if a lot of DOM work has been done in this session and a script tag |
| 117 // about to be parsed. This significantly improves render performance for docu
ments | 117 // is about to be parsed. This significantly improves render performance for |
| 118 // that place their scripts at the bottom of the page. Yielding too often | 118 // documents that place their scripts at the bottom of the page. Yielding too |
| 119 // significantly slows down the parsing so a balance needs to be struck to | 119 // often significantly slows down the parsing so a balance needs to be struck |
| 120 // only yield when enough changes have happened to make it worthwhile. | 120 // to only yield when enough changes have happened to make it worthwhile. |
| 121 // Emperical testing shows that anything > ~40 and < ~200 gives all of the ben
efit | 121 // Emperical testing shows that anything > ~40 and < ~200 gives all of the |
| 122 // without impacting parser performance, only adding a few yields per page but
at | 122 // benefit without impacting parser performance, only adding a few yields per |
| 123 // just the right times. | 123 // page but at just the right times. |
| 124 const size_t sufficientWork = 50; | 124 const size_t sufficientWork = 50; |
| 125 if (startingScript && session.processedElementTokens() > sufficientWork) | 125 if (startingScript && session.processedElementTokens() > sufficientWork) |
| 126 return true; | 126 return true; |
| 127 | 127 |
| 128 return false; | 128 return false; |
| 129 } | 129 } |
| 130 | 130 |
| 131 bool HTMLParserScheduler::yieldIfNeeded(const SpeculationsPumpSession& session, | 131 bool HTMLParserScheduler::yieldIfNeeded(const SpeculationsPumpSession& session, |
| 132 bool startingScript) { | 132 bool startingScript) { |
| 133 if (shouldYield(session, startingScript)) { | 133 if (shouldYield(session, startingScript)) { |
| 134 scheduleForResume(); | 134 scheduleForResume(); |
| 135 return true; | 135 return true; |
| 136 } | 136 } |
| 137 | 137 |
| 138 return false; | 138 return false; |
| 139 } | 139 } |
| 140 | 140 |
| 141 void HTMLParserScheduler::forceResumeAfterYield() { | 141 void HTMLParserScheduler::forceResumeAfterYield() { |
| 142 ASSERT(!m_cancellableContinueParse->isPending()); | 142 ASSERT(!m_cancellableContinueParse->isPending()); |
| 143 m_isSuspendedWithActiveTimer = true; | 143 m_isSuspendedWithActiveTimer = true; |
| 144 } | 144 } |
| 145 | 145 |
| 146 void HTMLParserScheduler::continueParsing() { | 146 void HTMLParserScheduler::continueParsing() { |
| 147 m_parser->resumeParsingAfterYield(); | 147 m_parser->resumeParsingAfterYield(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace blink | 150 } // namespace blink |
| OLD | NEW |