Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: Source/bindings/core/v8/ScriptStreamer.cpp

Issue 655263003: Script streaming: fix small script recognition heuristic. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: . Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "bindings/core/v8/ScriptStreamer.h" 6 #include "bindings/core/v8/ScriptStreamer.h"
7 7
8 #include "bindings/core/v8/ScriptStreamerThread.h" 8 #include "bindings/core/v8/ScriptStreamerThread.h"
9 #include "bindings/core/v8/V8ScriptRunner.h" 9 #include "bindings/core/v8/V8ScriptRunner.h"
10 #include "core/dom/Document.h" 10 #include "core/dom/Document.h"
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 ASSERT(!m_loadingFinished); 266 ASSERT(!m_loadingFinished);
267 m_streamingSuppressed = true; 267 m_streamingSuppressed = true;
268 } 268 }
269 269
270 void ScriptStreamer::notifyAppendData(ScriptResource* resource) 270 void ScriptStreamer::notifyAppendData(ScriptResource* resource)
271 { 271 {
272 ASSERT(isMainThread()); 272 ASSERT(isMainThread());
273 ASSERT(m_resource == resource); 273 ASSERT(m_resource == resource);
274 if (m_streamingSuppressed) 274 if (m_streamingSuppressed)
275 return; 275 return;
276 if (!m_firstDataChunkReceived) { 276 if (!m_haveEnoughDataForStreaming) {
277 m_firstDataChunkReceived = true; 277 // Even if the first data chunk is small, the script can still be big
278 const char* histogramName = startedStreamingHistogramName(m_scriptType); 278 // enough - wait until the next data chunk comes before deciding whether
279 // Check the size of the first data chunk. The expectation is that if 279 // to start the streaming.
280 // the first chunk is small, there won't be a second one. In those
281 // cases, it doesn't make sense to stream at all.
282 if (resource->resourceBuffer()->size() < kSmallScriptThreshold) { 280 if (resource->resourceBuffer()->size() < kSmallScriptThreshold) {
haraken 2014/10/22 14:20:39 What happens if the kSmallScriptThreshold is 1 KB
haraken 2014/10/22 14:25:27 Discussed offline. resource->resourceBuffer()->siz
283 suppressStreaming();
284 blink::Platform::current()->histogramEnumeration(histogramName, 0, 2 );
285 return; 281 return;
286 } 282 }
283 m_haveEnoughDataForStreaming = true;
284 const char* histogramName = startedStreamingHistogramName(m_scriptType);
287 if (ScriptStreamerThread::shared()->isRunningTask()) { 285 if (ScriptStreamerThread::shared()->isRunningTask()) {
288 // At the moment we only have one thread for running the tasks. A 286 // At the moment we only have one thread for running the tasks. A
289 // new task shouldn't be queued before the running task completes, 287 // new task shouldn't be queued before the running task completes,
290 // because the running task can block and wait for data from the 288 // because the running task can block and wait for data from the
291 // network. At the moment we are only streaming parser blocking 289 // network.
292 // scripts, but this code can still be hit when multiple frames are
293 // loading simultaneously.
294 suppressStreaming(); 290 suppressStreaming();
295 blink::Platform::current()->histogramEnumeration(histogramName, 0, 2 ); 291 blink::Platform::current()->histogramEnumeration(histogramName, 0, 2 );
296 return; 292 return;
297 } 293 }
298 ASSERT(m_task); 294 ASSERT(m_task);
299 // ScriptStreamer needs to stay alive as long as the background task is 295 // ScriptStreamer needs to stay alive as long as the background task is
300 // running. This is taken care of with a manual ref() & deref() pair; 296 // running. This is taken care of with a manual ref() & deref() pair;
301 // the corresponding deref() is in streamingComplete. 297 // the corresponding deref() is in streamingComplete.
302 ref(); 298 ref();
303 ScriptStreamingTask* task = new ScriptStreamingTask(m_task.release(), th is); 299 ScriptStreamingTask* task = new ScriptStreamingTask(m_task.release(), th is);
304 ScriptStreamerThread::shared()->postTask(task); 300 ScriptStreamerThread::shared()->postTask(task);
305 blink::Platform::current()->histogramEnumeration(histogramName, 1, 2); 301 blink::Platform::current()->histogramEnumeration(histogramName, 1, 2);
306 } 302 }
307 m_stream->didReceiveData(); 303 m_stream->didReceiveData();
308 } 304 }
309 305
310 void ScriptStreamer::notifyFinished(Resource* resource) 306 void ScriptStreamer::notifyFinished(Resource* resource)
311 { 307 {
312 ASSERT(isMainThread()); 308 ASSERT(isMainThread());
313 ASSERT(m_resource == resource); 309 ASSERT(m_resource == resource);
314 // A special case: empty scripts. We didn't receive any data before this 310 // A special case: empty and small scripts. We didn't receive enough data to
315 // notification. In that case, there won't be a "parsing complete" 311 // start the streaming before this notification. In that case, there won't
316 // notification either, and we should not wait for it. 312 // be a "parsing complete" notification either, and we should not wait for
317 if (!m_firstDataChunkReceived) 313 // it.
314 if (!m_haveEnoughDataForStreaming) {
315 const char* histogramName = startedStreamingHistogramName(m_scriptType);
316 blink::Platform::current()->histogramEnumeration(histogramName, 0, 2);
318 suppressStreaming(); 317 suppressStreaming();
318 }
319 m_stream->didFinishLoading(); 319 m_stream->didFinishLoading();
320 m_loadingFinished = true; 320 m_loadingFinished = true;
321 notifyFinishedToClient(); 321 notifyFinishedToClient();
322 } 322 }
323 323
324 ScriptStreamer::ScriptStreamer(ScriptResource* resource, v8::ScriptCompiler::Str eamedSource::Encoding encoding, PendingScript::Type scriptType) 324 ScriptStreamer::ScriptStreamer(ScriptResource* resource, v8::ScriptCompiler::Str eamedSource::Encoding encoding, PendingScript::Type scriptType)
325 : m_resource(resource) 325 : m_resource(resource)
326 , m_detached(false) 326 , m_detached(false)
327 , m_stream(new SourceStream(this)) 327 , m_stream(new SourceStream(this))
328 , m_source(m_stream, encoding) // m_source takes ownership of m_stream. 328 , m_source(m_stream, encoding) // m_source takes ownership of m_stream.
329 , m_client(0) 329 , m_client(0)
330 , m_loadingFinished(false) 330 , m_loadingFinished(false)
331 , m_parsingFinished(false) 331 , m_parsingFinished(false)
332 , m_firstDataChunkReceived(false) 332 , m_haveEnoughDataForStreaming(false)
333 , m_streamingSuppressed(false) 333 , m_streamingSuppressed(false)
334 , m_scriptType(scriptType) 334 , m_scriptType(scriptType)
335 { 335 {
336 } 336 }
337 337
338 void ScriptStreamer::notifyFinishedToClient() 338 void ScriptStreamer::notifyFinishedToClient()
339 { 339 {
340 ASSERT(isMainThread()); 340 ASSERT(isMainThread());
341 // Usually, the loading will be finished first, and V8 will still need some 341 // Usually, the loading will be finished first, and V8 will still need some
342 // time to catch up. But the other way is possible too: if V8 detects a 342 // time to catch up. But the other way is possible too: if V8 detects a
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 if (scriptStreamingTask) { 427 if (scriptStreamingTask) {
428 streamer->m_task = adoptPtr(scriptStreamingTask); 428 streamer->m_task = adoptPtr(scriptStreamingTask);
429 script.setStreamer(streamer.release()); 429 script.setStreamer(streamer.release());
430 return true; 430 return true;
431 } 431 }
432 // Otherwise, V8 cannot stream the script. 432 // Otherwise, V8 cannot stream the script.
433 return false; 433 return false;
434 } 434 }
435 435
436 } // namespace blink 436 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/ScriptStreamer.h ('k') | Source/bindings/core/v8/ScriptStreamerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698