text
stringlengths
1
372
switch in the DevTools performance view.
<topic_end>
<topic_start>
minimizing calls to saveLayer
can you avoid calls to saveLayer?
it might require rethinking of how you
create your visual effects:
note to package owners:
as a best practice, consider providing documentation
for when saveLayer might be necessary for your package,
how it might be avoided, and when it can’t be avoided.
other widgets that might trigger saveLayer()
and are potentially costly:
<topic_end>
<topic_start>
minimize use of opacity and clipping
opacity is another expensive operation, as is clipping.
here are some tips you might find to be useful:
<topic_end>
<topic_start>
implement grids and lists thoughtfully
how your grids and lists are implemented
might be causing performance problems for your app.
this section describes an important best
practice when creating grids and lists,
and how to determine whether your app uses
excessive layout passes.
<topic_end>
<topic_start>
be lazy!
when building a large grid or list,
use the lazy builder methods, with callbacks.
that ensures that only the visible portion of the
screen is built at startup time.
for more information and examples, check out:
<topic_end>
<topic_start>
avoid intrinsics
for information on how intrinsic passes might be causing
problems with your grids and lists, see the next section.
<topic_end>
<topic_start>
minimize layout passes caused by intrinsic operations
if you’ve done much flutter programming, you are
probably familiar with how layout and constraints work
when creating your UI. you might even have memorized flutter’s
basic layout rule: constraints go down. sizes go up.
parent sets position.
for some widgets, particularly grids and lists,
the layout process can be expensive.
flutter strives to perform just one layout pass
over the widgets but, sometimes,
a second pass (called an intrinsic pass) is needed,
and that can slow performance.
<topic_end>
<topic_start>
what is an intrinsic pass?
an intrinsic pass happens when, for example,
you want all cells to have the size
of the biggest or smallest cell (or some
similar calculation that requires polling all cells).
for example, consider a large grid of cards.
a grid should have uniformly sized cells,
so the layout code performs a pass,
starting from the root of the grid (in the widget tree),
asking each card in the grid (not just the
visible cards) to return
its intrinsic size—the size
that the widget prefers, assuming no constraints.
with this information,
the framework determines a uniform cell size,
and re-visits all grid cells a second time,
telling each card what size to use.
<topic_end>
<topic_start>
debugging intrinsic passes
to determine whether you have excessive intrinsic passes,
enable the track layouts option
in DevTools (disabled by default),
and look at the app’s stack trace
to learn how many layout passes were performed.
once you enable tracking, intrinsic timeline events
are labeled as ‘$runtimetype intrinsics’.
<topic_end>
<topic_start>
avoiding intrinsic passes
you have a couple options for avoiding the intrinsic pass:
to dive even deeper into how layout works,
check out the layout and rendering
section in the flutter architectural overview.
<topic_end>
<topic_start>
build and display frames in 16ms
since there are two separate threads for building
and rendering, you have 16ms for building,
and 16ms for rendering on a 60hz display.
if latency is a concern,
build and display a frame in 16ms or less.
note that means built in 8ms or less,
and rendered in 8ms or less,