Don't reset next work pointer for lower priority work
If the current work is higher priority than the new work, then don't bother resetting the unit of work pointer since it won't affect the execution order.
Sebastian Markbage committed
Jul 6, 2016 at 21:08 UTC
5c094fb5d1467e7b1fde823363fa4d1b9d8bdd11
2 files changed
+14
-5
src/renderers/shared/fiber/ReactFiberReconciler.js
+3
-3
@@ -73,7 +73,7 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) : Reconci
73
container.pendingProps = element;
74
container.pendingWorkPriority = LowPriority;
75
76
- scheduleLowPriWork(root);
76
+ scheduleLowPriWork(root, LowPriority);
77
78
// It may seem strange that we don't return the root here, but that will
79
// allow us to have containers that are in the middle of the tree instead
@@ -88,7 +88,7 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) : Reconci
88
root.current.pendingProps = element;
89
root.current.pendingWorkPriority = LowPriority;
90
91
- scheduleLowPriWork(root);
91
+ scheduleLowPriWork(root, LowPriority);
92
},
93
94
unmountContainer(container : OpaqueNode) : void {
@@ -98,7 +98,7 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) : Reconci
98
root.current.pendingProps = [];
99
root.current.pendingWorkPriority = LowPriority;
100
101
- scheduleLowPriWork(root);
101
+ scheduleLowPriWork(root, LowPriority);
102
},
103
104
getPublicRootInstance(container : OpaqueNode) : (C | null) {
src/renderers/shared/fiber/ReactFiberScheduler.js
+11
-2
@@ -15,6 +15,7 @@
15
import type { Fiber } from 'ReactFiber';
16
import type { FiberRoot } from 'ReactFiberRoot';
17
import type { HostConfig } from 'ReactFiberReconciler';
18
+import type { PriorityLevel } from 'ReactPriorityLevel';
19
20
var ReactFiberBeginWork = require('ReactFiberBeginWork');
21
var ReactFiberCompleteWork = require('ReactFiberCompleteWork');
@@ -43,6 +44,7 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
44
45
// The next work in progress fiber that we're currently working on.
46
let nextUnitOfWork : ?Fiber = null;
47
+ let nextPriorityLevel : PriorityLevel = NoWork;
48
49
// Linked list of roots with scheduled work on them.
50
let nextScheduledRoot : ?FiberRoot = null;
@@ -55,6 +57,7 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
57
if (nextScheduledRoot === lastScheduledRoot) {
58
nextScheduledRoot = null;
59
lastScheduledRoot = null;
60
+ nextPriorityLevel = NoWork;
61
return null;
62
}
63
nextScheduledRoot = nextScheduledRoot.nextScheduledRoot;
@@ -68,19 +71,23 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
71
// too many just means flushing changes too often.
72
let work = findNextUnitOfWorkAtPriority(root.current, HighPriority);
73
if (work) {
74
+ nextPriorityLevel = HighPriority;
75
return work;
76
}
77
work = findNextUnitOfWorkAtPriority(root.current, LowPriority);
78
if (work) {
79
+ nextPriorityLevel = LowPriority;
80
return work;
81
}
82
work = findNextUnitOfWorkAtPriority(root.current, OffscreenPriority);
83
if (work) {
84
+ nextPriorityLevel = OffscreenPriority;
85
return work;
86
}
87
// We didn't find anything to do in this root, so let's try the next one.
88
root = root.nextScheduledRoot;
89
}
90
+ nextPriorityLevel = NoWork;
91
return null;
92
}
93
@@ -208,11 +215,13 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
215
}
216
}
217
211
- function scheduleLowPriWork(root : FiberRoot) {
218
+ function scheduleLowPriWork(root : FiberRoot, priority : PriorityLevel) {
219
// We must reset the current unit of work pointer so that we restart the
220
// search from the root during the next tick, in case there is now higher
221
// priority work somewhere earlier than before.
215
- nextUnitOfWork = null;
222
+ if (priority <= nextPriorityLevel) {
223
+ nextUnitOfWork = null;
224
+ }
225
226
if (root.isScheduled) {
227
// If we're already scheduled, we can bail out.