Wednesday, January 10, 2024
HomeiOS Developmentios - SwiftUI 100% CPU + 1 MB reminiscence on textual content...

ios – SwiftUI 100% CPU + 1 MB reminiscence on textual content enter


TLDR: When focusing a TextField or TextEditor in a kind, every keystroke takes 100% CPU for as much as a second (earlier than returning to zero) and complete reminiscence goes up by practically a megabyte (and doesn’t come down).


Particulars:

  • XCode Model 15.1 (15C65)
  • iOS 17.0
  • Swift 5

I’m utilizing SwiftUI and SwiftData. The textual content editors bind to fields on a SwiftData mannequin. Past that, nothing too loopy is occurring, I’ve some onChange handlers however this conduct stays after they’re commented out.

The code is public, and the view containing the problematic fields is right here. I believe it has one thing to do with SwiftData however I don’t know why – this conduct appears to have come out of nowhere however frankly my work is not sufficiently organized to bisect its origin.

I am unsure I can extract this right into a minimal instance given the spaghetti nature of my code – I simply need to make my app usable once more if anybody with SwiftData/CoreData expertise has any fast ideas for me.

  1. I eliminated any onChange and onAppear handlers from the fields – conduct remained
  2. I eliminated the modelContext from the offending view, as an alternative passing obligatory helpers in a closure – the conduct remained

I’ve carried out just a few different issues however actually I’ll retry something if another person tells me to; I’m not skilled sufficient with SwiftUI to debug successfully.

EDIT:

Primarily based on some extra profiling, it looks like every replace to those fashions re-queries each single SwiftData mannequin. I assume this implies the foundation view is being redrawn (the bottom of a NavigationStack), however I am unable to perceive why or easy methods to cease it.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments