Unverified Commit 66a67263 authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Fix benchmark regression in layer.find<S>(Offset) (#32425)

This fixes a benchmark regression introduced in #32350. The performance is improved by just reverting the Layer.find<S> routines to use their old definitions, instead of defining them in terms of the findAll<S> lazy iterators.

Fixes #32387
parent 3436e165
...@@ -634,11 +634,15 @@ class ContainerLayer extends Layer { ...@@ -634,11 +634,15 @@ class ContainerLayer extends Layer {
@override @override
S find<S>(Offset regionOffset) { S find<S>(Offset regionOffset) {
final Iterable<S> all = findAll<S>(regionOffset); Layer current = lastChild;
if (all.isEmpty) { while (current != null) {
return null; final Object value = current.find<S>(regionOffset);
if (value != null) {
return value;
}
current = current.previousSibling;
} }
return all.first; return null;
} }
@override @override
...@@ -1263,26 +1267,31 @@ class TransformLayer extends OffsetLayer { ...@@ -1263,26 +1267,31 @@ class TransformLayer extends OffsetLayer {
return null; // this does not return an engine layer yet. return null; // this does not return an engine layer yet.
} }
@override Offset _transformOffset(Offset regionOffset) {
S find<S>(Offset regionOffset) {
final Iterable<S> all = findAll<S>(regionOffset);
if (all.isEmpty) {
return null;
}
return all.first;
}
@override
Iterable<S> findAll<S>(Offset regionOffset) sync* {
if (_inverseDirty) { if (_inverseDirty) {
_invertedTransform = Matrix4.tryInvert(transform); _invertedTransform = Matrix4.tryInvert(transform);
_inverseDirty = false; _inverseDirty = false;
} }
if (_invertedTransform == null) if (_invertedTransform == null)
return; return null;
final Vector4 vector = Vector4(regionOffset.dx, regionOffset.dy, 0.0, 1.0); final Vector4 vector = Vector4(regionOffset.dx, regionOffset.dy, 0.0, 1.0);
final Vector4 result = _invertedTransform.transform(vector); final Vector4 result = _invertedTransform.transform(vector);
yield* super.findAll<S>(Offset(result[0], result[1])); return Offset(result[0], result[1]);
}
@override
S find<S>(Offset regionOffset) {
final Offset transformedOffset = _transformOffset(regionOffset);
return transformedOffset == null ? null : super.find<S>(transformedOffset);
}
@override
Iterable<S> findAll<S>(Offset regionOffset) sync* {
final Offset transformedOffset = _transformOffset(regionOffset);
if (transformedOffset == null) {
return;
}
yield* super.findAll<S>(transformedOffset);
} }
@override @override
...@@ -1588,11 +1597,9 @@ class PhysicalModelLayer extends ContainerLayer { ...@@ -1588,11 +1597,9 @@ class PhysicalModelLayer extends ContainerLayer {
@override @override
S find<S>(Offset regionOffset) { S find<S>(Offset regionOffset) {
final Iterable<S> all = findAll<S>(regionOffset); if (!clipPath.contains(regionOffset))
if (all.isEmpty) {
return null; return null;
} return super.find<S>(regionOffset);
return all.first;
} }
@override @override
...@@ -1844,11 +1851,11 @@ class FollowerLayer extends ContainerLayer { ...@@ -1844,11 +1851,11 @@ class FollowerLayer extends ContainerLayer {
@override @override
S find<S>(Offset regionOffset) { S find<S>(Offset regionOffset) {
final Iterable<S> all = findAll<S>(regionOffset); if (link.leader == null) {
if (all.isEmpty) { return showWhenUnlinked ? super.find<S>(regionOffset - unlinkedOffset) : null;
return null;
} }
return all.first; final Offset transformedOffset = _transformOffset<S>(regionOffset);
return transformedOffset == null ? null : super.find<S>(transformedOffset);
} }
@override @override
...@@ -1856,7 +1863,11 @@ class FollowerLayer extends ContainerLayer { ...@@ -1856,7 +1863,11 @@ class FollowerLayer extends ContainerLayer {
if (link.leader == null) { if (link.leader == null) {
return showWhenUnlinked ? super.findAll<S>(regionOffset - unlinkedOffset) : <S>[]; return showWhenUnlinked ? super.findAll<S>(regionOffset - unlinkedOffset) : <S>[];
} }
return super.findAll<S>(_transformOffset<S>(regionOffset)); final Offset transformedOffset = _transformOffset<S>(regionOffset);
if (transformedOffset == null) {
return <S>[];
}
return super.findAll<S>(transformedOffset);
} }
/// The transform that was used during the last composition phase. /// The transform that was used during the last composition phase.
...@@ -2031,11 +2042,17 @@ class AnnotatedRegionLayer<T> extends ContainerLayer { ...@@ -2031,11 +2042,17 @@ class AnnotatedRegionLayer<T> extends ContainerLayer {
@override @override
S find<S>(Offset regionOffset) { S find<S>(Offset regionOffset) {
final Iterable<S> all = findAll<S>(regionOffset); final S result = super.find<S>(regionOffset);
if (all.isEmpty) { if (result != null)
return result;
if (size != null && !(offset & size).contains(regionOffset))
return null; return null;
if (T == S) {
final Object untypedResult = value;
final S typedResult = untypedResult;
return typedResult;
} }
return all.first; return super.find<S>(regionOffset);
} }
@override @override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment