Skip to content
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

XML parse blocks main thread #233

Open
tomasbek opened this issue Dec 3, 2022 · 2 comments
Open

XML parse blocks main thread #233

tomasbek opened this issue Dec 3, 2022 · 2 comments

Comments

@tomasbek
Copy link

tomasbek commented Dec 3, 2022

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
Copy link

I suspect this is concurrency problem rather than SwiftSoup issue, can you try running the operation on different queues?

@aehlke
Copy link
Contributor

aehlke commented Mar 19, 2024

this isn't a library issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants