New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
High CPU usage #10
Comments
I won't be able to test this until tomorrow, but when I do it would speed up testing if I know what device(s) you have tested this on (phone, iPad, simulator, physical, etc.). |
This was tested on an iPhone 12 and an iPhone 8 Plus, both running iOS 14.2.1. |
Physical or simulator? |
I only tested on physical devices. |
I was afraid of that. I'll look into this asap, thanks for letting me know! |
I got a workaround. When I change the As soon as it has the Edit: When I use |
I was able to reproduce the issue, and I have an idea what's causing it. If my hunch is correct, this is a bug in SwiftUI itself, though I haven't finished my analysis yet so it could be a bug in my code. In either case, the quick fix is to not store the search text in an observable object. Having an inline struct ContentView: View {
@State var searchText = ""
var body: some View {
NavigationView {
List {
Text("foo")
}.navigationBarSearch($searchText)
}
}
} |
Was just trying to debug this behavior in my app. It seems the view keeps being rebuilt even when text isn't changing. You can set a breakpoint in the view and it will keep getting hit with no user interaction. This doesn't happen with a regular var body: some View {
NavigationView {
List {
TextField("Input", text: $viewModel.searchText)
Text("foo")
}//.navigationBarSearch($viewModel.searchText)
}
}
|
@JoeLago are you sure this persists in 1.2.3? My testing showed that the cpu dropped to 0% at idle after the change. |
You can reproduce it with the code that I shared originally, but it won't happen as soon as you open the screen. If you initially open the screen the CPU usage will be at 0%. However, this changes as soon as you type something into the search bar. Then the CPU usage will shoot up again and won't go down after a while. |
Strange, I saw the spike when typing when it always went back down to 0 after you stopped for me. I'll take another look. |
Looks like the CPU usage will only be high, if there is something typed in the searchbar. If you clear out the text it will be down to 0% again. |
When using the search bar I get a high CPU usage (100% usage consistently), even when the user has not interacted with the search bar or the app at all. I only tested this on iOS 14.2.1.
Here is an example of how the high CPU usage can be reproduced quite easily:
As soon as the
.navigationBarSearch
is commented out, the high CPU usage disappears.Am I doing something wrong here or could this be a bug?
The text was updated successfully, but these errors were encountered: