XML parse blocks main thread
tomasbek opened this issue · 3 comments
tomasbek commented
Dear all,
I use SwiftSoup to extract XML data for my SwiftUI app. It works perfectly but recently I run up to a problem when working with very large XML files (10000 lines). Even though I use SwiftUI's async and task functionality to parse the data in the background, it still blocks the main thread.
Please see the sample code below to explain the situation.
@State var data: [Element] = []
List {
ForEach(data) { element in
ElementRow(element: element)
}
}
.task {
let (data, _) = try await session.data(from: some url)
let xml = String(data: data, encoding: .utf8)
let document = try SwiftSoup.parse(xml, "", Parser.xmlParser()) // <- This is where the hang comes up from
<...>
self.data = result
}
Any ideas on way forward to avoid the app hanging up while SwiftSoup parses large XML file?
Thanks!
rohit9934 commented
I suspect this is concurrency problem rather than SwiftSoup issue, can you try running the operation on different queues?
aehlke commented
this isn't a library issue