Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
38604989
Unverified
Commit
38604989
authored
Sep 15, 2022
by
Polina Cherkasova
Committed by
GitHub
Sep 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix performance regression. (#111615)
parent
96b49aae
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
55 deletions
+39
-55
change_notifier.dart
packages/flutter/lib/src/foundation/change_notifier.dart
+11
-15
memory_allocations.dart
packages/flutter/lib/src/foundation/memory_allocations.dart
+20
-32
memory_allocations_test.dart
...ages/flutter/test/foundation/memory_allocations_test.dart
+8
-8
No files found.
packages/flutter/lib/src/foundation/change_notifier.dart
View file @
38604989
...
...
@@ -215,13 +215,11 @@ class ChangeNotifier implements Listenable {
void
addListener
(
VoidCallback
listener
)
{
assert
(
ChangeNotifier
.
debugAssertNotDisposed
(
this
));
if
(
kFlutterMemoryAllocationsEnabled
&&
!
_creationDispatched
)
{
MemoryAllocations
.
instance
.
dispatchObjectEvent
(()
{
return
ObjectCreated
(
library
:
_flutterFoundationLibrary
,
className:
'ChangeNotifier'
,
object:
this
,
);
});
MemoryAllocations
.
instance
.
dispatchObjectEvent
(
ObjectCreated
(
library
:
_flutterFoundationLibrary
,
className:
'ChangeNotifier'
,
object:
this
,
));
_creationDispatched
=
true
;
}
if
(
_count
==
_listeners
.
length
)
{
...
...
@@ -328,7 +326,7 @@ class ChangeNotifier implements Listenable {
return
true
;
}());
if
(
kFlutterMemoryAllocationsEnabled
&&
_creationDispatched
)
{
MemoryAllocations
.
instance
.
dispatchObjectEvent
(
()
=>
ObjectDisposed
(
object:
this
));
MemoryAllocations
.
instance
.
dispatchObjectEvent
(
ObjectDisposed
(
object:
this
));
}
_listeners
=
_emptyListeners
;
_count
=
0
;
...
...
@@ -466,13 +464,11 @@ class ValueNotifier<T> extends ChangeNotifier implements ValueListenable<T> {
/// Creates a [ChangeNotifier] that wraps this value.
ValueNotifier
(
this
.
_value
)
{
if
(
kFlutterMemoryAllocationsEnabled
)
{
MemoryAllocations
.
instance
.
dispatchObjectEvent
(()
{
return
ObjectCreated
(
library
:
_flutterFoundationLibrary
,
className:
'ValueNotifier'
,
object:
this
,
);
});
MemoryAllocations
.
instance
.
dispatchObjectEvent
(
ObjectCreated
(
library
:
_flutterFoundationLibrary
,
className:
'ValueNotifier'
,
object:
this
,
));
}
_creationDispatched
=
true
;
}
...
...
packages/flutter/lib/src/foundation/memory_allocations.dart
View file @
38604989
...
...
@@ -12,11 +12,11 @@ const bool _kMemoryAllocations = bool.fromEnvironment('flutter.memory_allocation
/// If true, Flutter objects dispatch the memory allocation events.
///
/// By default, the constant is true for
profile and
debug mode and false
/// for
release mode, for app size optimization goal
s.
/// By default, the constant is true for debug mode and false
/// for
profile and release mode
s.
/// To enable the dispatching for release mode, pass the compilation flag
/// `--dart-define=flutter.memory_allocations=true`.
const
bool
kFlutterMemoryAllocationsEnabled
=
_kMemoryAllocations
||
k
ProfileMode
||
k
DebugMode
;
const
bool
kFlutterMemoryAllocationsEnabled
=
_kMemoryAllocations
||
kDebugMode
;
const
String
_dartUiLibrary
=
'dart:ui'
;
...
...
@@ -54,9 +54,6 @@ abstract class ObjectEvent{
/// A listener of [ObjectEvent].
typedef
ObjectEventListener
=
void
Function
(
ObjectEvent
);
/// A builder of [ObjectEvent].
typedef
ObjectEventBuilder
=
ObjectEvent
Function
();
/// An event that describes creation of an object.
class
ObjectCreated
extends
ObjectEvent
{
/// Creates an instance of [ObjectCreated].
...
...
@@ -225,7 +222,7 @@ class MemoryAllocations {
/// after the removal.
///
/// Only call this when [kFlutterMemoryAllocationsEnabled] is true.
void
dispatchObjectEvent
(
ObjectEvent
Builder
objectEventBuilder
)
{
void
dispatchObjectEvent
(
ObjectEvent
event
)
{
if
(!
kFlutterMemoryAllocationsEnabled
)
{
return
;
}
...
...
@@ -234,7 +231,6 @@ class MemoryAllocations {
return
;
}
final
ObjectEvent
event
=
objectEventBuilder
();
_activeDispatchLoops
++;
final
int
end
=
listeners
.
length
;
for
(
int
i
=
0
;
i
<
end
;
i
++)
{
...
...
@@ -285,38 +281,30 @@ class MemoryAllocations {
}
void
_imageOnCreate
(
ui
.
Image
image
)
{
dispatchObjectEvent
(()
{
return
ObjectCreated
(
library
:
_dartUiLibrary
,
className:
'Image'
,
object:
image
,
);
});
dispatchObjectEvent
(
ObjectCreated
(
library
:
_dartUiLibrary
,
className:
'Image'
,
object:
image
,
));
}
void
_pictureOnCreate
(
ui
.
Picture
picture
)
{
dispatchObjectEvent
(()
{
return
ObjectCreated
(
library
:
_dartUiLibrary
,
className:
'Picture'
,
object:
picture
,
);
});
dispatchObjectEvent
(
ObjectCreated
(
library
:
_dartUiLibrary
,
className:
'Picture'
,
object:
picture
,
));
}
void
_imageOnDispose
(
ui
.
Image
image
)
{
dispatchObjectEvent
(()
{
return
ObjectDisposed
(
object:
image
,
);
});
dispatchObjectEvent
(
ObjectDisposed
(
object:
image
,
));
}
void
_pictureOnDispose
(
ui
.
Picture
picture
)
{
dispatchObjectEvent
(()
{
return
ObjectDisposed
(
object:
picture
,
);
});
dispatchObjectEvent
(
ObjectDisposed
(
object:
picture
,
));
}
}
packages/flutter/test/foundation/memory_allocations_test.dart
View file @
38604989
...
...
@@ -24,13 +24,13 @@ void main() {
ma
.
addListener
(
listener
);
_checkSdkHandlersSet
();
ma
.
dispatchObjectEvent
(
()
=>
event
);
ma
.
dispatchObjectEvent
(
event
);
expect
(
recievedEvent
,
equals
(
event
));
expect
(
ma
.
hasListeners
,
isTrue
);
recievedEvent
=
null
;
ma
.
removeListener
(
listener
);
ma
.
dispatchObjectEvent
(
()
=>
event
);
ma
.
dispatchObjectEvent
(
event
);
expect
(
recievedEvent
,
isNull
);
expect
(
ma
.
hasListeners
,
isFalse
);
_checkSdkHandlersNotSet
();
...
...
@@ -56,7 +56,7 @@ void main() {
ma
.
addListener
(
badListener2
);
ma
.
addListener
(
listener2
);
ma
.
dispatchObjectEvent
(
()
=>
event
);
ma
.
dispatchObjectEvent
(
event
);
expect
(
log
,
<
String
>[
'badListener1'
,
'listener1'
,
'badListener2'
,
'listener2'
]);
expect
(
tester
.
takeException
(),
contains
(
'Multiple exceptions (2)'
));
...
...
@@ -69,7 +69,7 @@ void main() {
log
.
clear
();
expect
(
ma
.
hasListeners
,
isFalse
);
ma
.
dispatchObjectEvent
(
()
=>
event
);
ma
.
dispatchObjectEvent
(
event
);
expect
(
log
,
<
String
>[]);
});
...
...
@@ -86,11 +86,11 @@ void main() {
ma
.
addListener
(
listener1
);
_checkSdkHandlersSet
();
ma
.
dispatchObjectEvent
(
()
=>
event
);
ma
.
dispatchObjectEvent
(
event
);
expect
(
log
,
<
String
>[
'listener1'
]);
log
.
clear
();
ma
.
dispatchObjectEvent
(
()
=>
event
);
ma
.
dispatchObjectEvent
(
event
);
expect
(
log
,
<
String
>[
'listener1'
,
'listener2'
]);
log
.
clear
();
...
...
@@ -99,7 +99,7 @@ void main() {
_checkSdkHandlersNotSet
();
expect
(
ma
.
hasListeners
,
isFalse
);
ma
.
dispatchObjectEvent
(
()
=>
event
);
ma
.
dispatchObjectEvent
(
event
);
expect
(
log
,
<
String
>[]);
});
...
...
@@ -117,7 +117,7 @@ void main() {
ma
.
addListener
(
listener1
);
ma
.
addListener
(
listener2
);
ma
.
dispatchObjectEvent
(
()
=>
event
);
ma
.
dispatchObjectEvent
(
event
);
expect
(
log
,
<
String
>[
'listener1'
]);
log
.
clear
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment