Replies: 2 comments 1 reply
-
Hey @fabstu! This is a good idea, but are you aware of the It doesn't mean that interesting metrics like counts and timings shouldn't be observed, but I feel they could probably be more useful if defined as general utilities, out of some From my experience a few months ago, |
Beta Was this translation helpful? Give feedback.
-
Counting invocationsI extended Branch based on 0.47.2: https://github.com/fabstu/swift-composable-architecture/tree/exp-render-instrumentation Usage: Add Example output before:
Example output after looking up parts that shouldn't be re-rendered:
The whole thing is pretty illuminating. I instantly found two places that shouldn't re-render. What especially stands out is parts with the big diffs. These might have to be scoped more in the first place. Notesinternal views not setting their Prefix and not taking file/line/prefix arguments.Added some to
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It is sometimes more difficult than necessary to find what WithViewStore body excessively re-renders (the only way I know is looking at the Timing Summary from Xcode Instruments/SwiftUI/ViewBody and guessing by what else re-rendered). Why don't we augment
WithViewStore.body
with the following line to make it print to console each time the body is re-rendered? Performance problems become glaringly obvious. The first line of a re-render hierarchy may be the culprit for the lines after (not sure whether the assumption that parent-user ofWithViewStore
gets re-evaluated before child is true, but we will know..).Output:
When a view containg the
WithViewStore
is reused, we get into the same issue as with usingWithViewStore
: seeing the type in "Timing Summary" (XCode Instruments/SwiftUI/View Body) is not enough to deduce the user of the view. For such cases, we can augment the parent view with fileID and line as well. For exampleCounterView
:which then prints the user of
CounterView
each time theWithViewStore
re-renders.How this should be enabled is unclear. Options I see:
The next step to do after knowing what unexpectedly re-renders can be to add
Self._printChanges()
.Other ideas:
53x WithViewStore SwiftUICaseStudies/01-GettingStarted-Composition-TwoCounters.swift#47 <SwiftUICaseStudies.Counter.State, SwiftUICaseStudies.Counter.Action, ...>
Beta Was this translation helpful? Give feedback.
All reactions