Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f17919b

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[nnbd/corelib] Fix performance regression in _SyncIterator.moveNext
In Iteration.deeptree.syncstar benchmark _SyncIterator.moveNext takes majority of time. If _moveNextFn is cached in a local variable, then loading a function object out of _moveNextFn closure is hoisted out of the loop and executed even if _moveNextFn is not called. The function and cached moveNextFn are also saved to frame. This extra code results in a slight slowdown of _SyncIterator.moveNext when _yieldEachIterator != null. Iteration.deeptree.syncstar(RunTime) 98877 -> 81541 us (with NNBD core libraries) Change-Id: Ieac94e106632f9c923eb72d9221bcdecb52fa652 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138609 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 6b71477 commit f17919b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

sdk_nnbd/lib/_internal/vm/lib/core_patch.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ class _SyncIterator<T> implements Iterator<T> {
136136
_SyncIterator(this._moveNextFn);
137137

138138
bool moveNext() {
139-
final moveNextFn = _moveNextFn;
140-
if (moveNextFn == null) {
139+
if (_moveNextFn == null) {
141140
return false;
142141
}
143142
while (true) {
@@ -150,7 +149,7 @@ class _SyncIterator<T> implements Iterator<T> {
150149
}
151150
// _moveNextFn() will update the values of _yieldEachIterable
152151
// and _current.
153-
if (!moveNextFn(this)) {
152+
if (!_moveNextFn!(this)) {
154153
_moveNextFn = null;
155154
_current = null;
156155
return false;

0 commit comments

Comments
 (0)