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

Side by Side Diff: components/scheduler/renderer/renderer_scheduler_impl.cc

Issue 1420773003: scheduler: Don't block expensive loading tasks during main thread gestures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments. Created 5 years, 1 month 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
« no previous file with comments | « no previous file | components/scheduler/renderer/renderer_scheduler_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/scheduler/renderer/renderer_scheduler_impl.h" 5 #include "components/scheduler/renderer/renderer_scheduler_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/stack_trace.h" 8 #include "base/debug/stack_trace.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "base/trace_event/trace_event_argument.h" 10 #include "base/trace_event/trace_event_argument.h"
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 603
604 if (new_policy_duration > base::TimeDelta()) { 604 if (new_policy_duration > base::TimeDelta()) {
605 MainThreadOnly().current_policy_expiration_time = now + new_policy_duration; 605 MainThreadOnly().current_policy_expiration_time = now + new_policy_duration;
606 delayed_update_policy_runner_.SetDeadline(FROM_HERE, new_policy_duration, 606 delayed_update_policy_runner_.SetDeadline(FROM_HERE, new_policy_duration,
607 now); 607 now);
608 } else { 608 } else {
609 MainThreadOnly().current_policy_expiration_time = base::TimeTicks(); 609 MainThreadOnly().current_policy_expiration_time = base::TimeTicks();
610 } 610 }
611 611
612 Policy new_policy; 612 Policy new_policy;
613 bool block_expensive_tasks = false; 613 bool block_expensive_loading_tasks = false;
614 bool block_expensive_timer_tasks = false;
614 switch (use_case) { 615 switch (use_case) {
615 case UseCase::COMPOSITOR_GESTURE: 616 case UseCase::COMPOSITOR_GESTURE:
616 if (touchstart_expected_soon) { 617 if (touchstart_expected_soon) {
617 block_expensive_tasks = true; 618 block_expensive_loading_tasks = true;
619 block_expensive_timer_tasks = true;
618 } else { 620 } else {
619 // What we really want to do is priorize loading tasks, but that doesn't 621 // What we really want to do is priorize loading tasks, but that doesn't
620 // seem to be safe. Instead we do that by proxy by deprioritizing 622 // seem to be safe. Instead we do that by proxy by deprioritizing
621 // compositor tasks. This should be safe since we've already gone to the 623 // compositor tasks. This should be safe since we've already gone to the
622 // pain of fixing ordering issues with them. 624 // pain of fixing ordering issues with them.
623 new_policy.compositor_queue_priority = TaskQueue::BEST_EFFORT_PRIORITY; 625 new_policy.compositor_queue_priority = TaskQueue::BEST_EFFORT_PRIORITY;
624 } 626 }
625 break; 627 break;
626 628
627 case UseCase::MAIN_THREAD_GESTURE: 629 case UseCase::MAIN_THREAD_GESTURE:
630 // In main thread gestures we don't have perfect knowledge about which
631 // things we should be prioritizing. The following is best guess
632 // heuristic which lets us produce frames quickly but does not prevent
633 // loading of additional content.
628 new_policy.compositor_queue_priority = TaskQueue::HIGH_PRIORITY; 634 new_policy.compositor_queue_priority = TaskQueue::HIGH_PRIORITY;
629 block_expensive_tasks = true; 635 block_expensive_loading_tasks = false;
636 block_expensive_timer_tasks = true;
630 break; 637 break;
631 638
632 case UseCase::TOUCHSTART: 639 case UseCase::TOUCHSTART:
633 new_policy.compositor_queue_priority = TaskQueue::HIGH_PRIORITY; 640 new_policy.compositor_queue_priority = TaskQueue::HIGH_PRIORITY;
634 new_policy.loading_queue_priority = TaskQueue::DISABLED_PRIORITY; 641 new_policy.loading_queue_priority = TaskQueue::DISABLED_PRIORITY;
635 new_policy.timer_queue_priority = TaskQueue::DISABLED_PRIORITY; 642 new_policy.timer_queue_priority = TaskQueue::DISABLED_PRIORITY;
636 block_expensive_tasks = true; // NOTE this is a nop due to the above. 643 // NOTE these are nops due to the above.
644 block_expensive_loading_tasks = true;
645 block_expensive_timer_tasks = true;
637 break; 646 break;
638 647
639 case UseCase::NONE: 648 case UseCase::NONE:
640 if (touchstart_expected_soon) 649 if (touchstart_expected_soon) {
641 block_expensive_tasks = true; 650 block_expensive_loading_tasks = true;
651 block_expensive_timer_tasks = true;
652 }
642 break; 653 break;
643 654
644 case UseCase::LOADING: 655 case UseCase::LOADING:
645 new_policy.loading_queue_priority = TaskQueue::HIGH_PRIORITY; 656 new_policy.loading_queue_priority = TaskQueue::HIGH_PRIORITY;
646 new_policy.default_queue_priority = TaskQueue::HIGH_PRIORITY; 657 new_policy.default_queue_priority = TaskQueue::HIGH_PRIORITY;
647 break; 658 break;
648 659
649 default: 660 default:
650 NOTREACHED(); 661 NOTREACHED();
651 } 662 }
652 663
653 // Don't block expensive tasks unless we have actually seen something. 664 // Don't block expensive tasks unless we have actually seen something.
654 if (!MainThreadOnly().have_seen_a_begin_main_frame) 665 if (!MainThreadOnly().have_seen_a_begin_main_frame) {
655 block_expensive_tasks = false; 666 block_expensive_loading_tasks = false;
667 block_expensive_timer_tasks = false;
668 }
656 669
657 // Don't block expensive tasks if we are expecting a navigation. 670 // Don't block expensive tasks if we are expecting a navigation.
658 if (MainThreadOnly().navigation_task_expected_count > 0) 671 if (MainThreadOnly().navigation_task_expected_count > 0) {
659 block_expensive_tasks = false; 672 block_expensive_loading_tasks = false;
673 block_expensive_timer_tasks = false;
674 }
660 675
661 if (block_expensive_tasks && loading_tasks_seem_expensive) 676 if (block_expensive_loading_tasks && loading_tasks_seem_expensive)
662 new_policy.loading_queue_priority = TaskQueue::DISABLED_PRIORITY; 677 new_policy.loading_queue_priority = TaskQueue::DISABLED_PRIORITY;
663 678
664 if ((block_expensive_tasks && timer_tasks_seem_expensive) || 679 if ((block_expensive_timer_tasks && timer_tasks_seem_expensive) ||
665 MainThreadOnly().timer_queue_suspend_count != 0 || 680 MainThreadOnly().timer_queue_suspend_count != 0 ||
666 MainThreadOnly().timer_queue_suspended_when_backgrounded) { 681 MainThreadOnly().timer_queue_suspended_when_backgrounded) {
667 new_policy.timer_queue_priority = TaskQueue::DISABLED_PRIORITY; 682 new_policy.timer_queue_priority = TaskQueue::DISABLED_PRIORITY;
668 } 683 }
669 684
670 // Tracing is done before the early out check, because it's quite possible we 685 // Tracing is done before the early out check, because it's quite possible we
671 // will otherwise miss this information in traces. 686 // will otherwise miss this information in traces.
672 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( 687 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
673 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", 688 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler",
674 this, AsValueLocked(now)); 689 this, AsValueLocked(now));
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 any_thread_lock_.AssertAcquired(); 965 any_thread_lock_.AssertAcquired();
951 MainThreadOnly().loading_task_cost_estimator.Clear(); 966 MainThreadOnly().loading_task_cost_estimator.Clear();
952 MainThreadOnly().timer_task_cost_estimator.Clear(); 967 MainThreadOnly().timer_task_cost_estimator.Clear();
953 MainThreadOnly().idle_time_estimator.Clear(); 968 MainThreadOnly().idle_time_estimator.Clear();
954 AnyThread().user_model.Reset(helper_.Now()); 969 AnyThread().user_model.Reset(helper_.Now());
955 MainThreadOnly().have_seen_a_begin_main_frame = false; 970 MainThreadOnly().have_seen_a_begin_main_frame = false;
956 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); 971 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED);
957 } 972 }
958 973
959 } // namespace scheduler 974 } // namespace scheduler
OLDNEW
« no previous file with comments | « no previous file | components/scheduler/renderer/renderer_scheduler_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698