-
Notifications
You must be signed in to change notification settings - Fork 14
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
Wrapping Jsoup on JVM to improve performance #79
Comments
There are some impliciations though - by having two different implementations, Ksoup might return different results on different targets. Consider if Ksoup ports Jsoup 1.0 to Kotlin Native, and depends on Jsoup 1.0 on the JVM. In a future Jsoup 1.1 release it fixes a bug which led to wrong selector results. Now, if a user have Jsoup 1.1 dependency locally, which will override Ksoup's dependency, they will see inconsisitent results across targets. But I'm personally happy with this inconsistency, because Jsoup is very stable and this is unlikely to happen. |
@Him188 Thank you for your feedback! However, I currently have no plans to wrap Jsoup for the JVM, as it could lead to inconsistencies and increased complexity. At the moment, Jsoup is 2-3 times faster only for parsing, but query performance is the same. I have just completed the |
Follow up on: #80 |
Hi, as a follow up of #39, I'm considering if we can make Ksoup a wrapper of Jsoup on JVM.
Here are some reasons:
My app previously target desktop JVM and Android so it was using Jsoup. Ksoup allows us to support iOS without chaning code which very nice, however we can't accept any performance degredation on the JVM, because the parsing is in a critical user path such that performance directly affect user experience. Therefore, I can't switch the common code to Ksoup unless Ksoup perform the same well as Jsoup on JVM.
I finally ended up adopting some compiler magic that creating
expect clas
Element
,Node
,Document
, etc. in thecommonMain
, actualizing it to Jsoup on the JVM, and actualizing to Ksoup on Native. Errors suppressed.Relevant source code:
Jsoup
andKsoup
classes:https://github.com/open-ani/ani/blob/f69544871dc451198173adc5370e46465472c5dc/utils/xml/src/commonMain/kotlin/Xml.kt#L6
https://github.com/open-ani/ani/blob/e2b8ffea02f6a52faaaa010112d67bdec8b1560c/utils/xml/src/jvmMain/kotlin/Xml.jvm.kt#L8
https://github.com/open-ani/ani/blob/e2b8ffea02f6a52faaaa010112d67bdec8b1560c/utils/xml/src/commonMain/kotlin/DocumentPort.kt#L6-L5
DocumentPort.jvm.kt:7
So, I'm considering if Ksoup can use Jsoup on the JVM, hence getting the best performance. This would help everyone who needs to concern about performance.
Technically Ksoup can't do this magic - it's too risky to do as a library. I assume it can be achieved by turning Ksoups's
Element
classes to become a delegate of Jsoup's corresponding part. The only overhead is the wrapper class - which is just one object can is acceptable.But again, thats for your tarrific work of creating Ksoup. Looking forward to your replies!
The text was updated successfully, but these errors were encountered: