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

Query reg Performance upgradation #262

Closed
LogeswaranRamasamy opened this issue Jan 24, 2025 · 4 comments
Closed

Query reg Performance upgradation #262

LogeswaranRamasamy opened this issue Jan 24, 2025 · 4 comments

Comments

@LogeswaranRamasamy
Copy link

Is there any Multiplatform compatible way to Read/Write XML File during Serialization & Deserialization efficiently ?

I tried xml.decodeFromString(string) but it seems to bit slow as it appears to follow DOM approach. Instead I am looking for something similar to StAx parser offering performance as Data I am working on will be pretty huge.

The Data I am working will be available as String, so issues in reading it as multiplatform solution.

@pdvrieze
Copy link
Owner

As mentioned in #188, the multiplatform way is to use KtXmlReader (or xmlstreaming.newGenericReader). That will give you effectively a stax parser. For performance you also want to store the format, as that will cache the data structure (which is independent of the actual data, only depending on the types/serializers/serial descriptors)

@LogeswaranRamasamy
Copy link
Author

LogeswaranRamasamy commented Jan 24, 2025

I tried but unable to construct Reader Object that needs to be passed for xmlstreaming.newGenericReader, couldn't find any resource/example reg constructing ktXmlReader/xmlstreaming.newGenericReader from String. Is there any example available for reference.

For performance you also want to store the format, as that will cache the data structure (which is independent of the actual data, only depending on the types/serializers/serial descriptors)

Yes I am enabling isCachingEnabled = true flag while configuring xml serialiser.

fun getXmlConfig() = XML(getModule()) {
    xmlDeclMode = XmlDeclMode.Charset
    autoPolymorphic = true
    repairNamespaces = true
    indentString = "    "
    indent = 1
    policy = xmlpolicy
   isCachingEnabled = true    
}

@pdvrieze
Copy link
Owner

@LogeswaranRamasamy In the test suite for the core module the newGenericReader function is used (albeit by reference):

class TestKtXmlReader : TestCommonReader() {
private fun createReader(it: String): XmlReader = xmlStreaming.newGenericReader(it)
@Test
fun testReadCompactFragmentWithNamespaceInOuter() {
testReadCompactFragmentWithNamespaceInOuter(::createReader)
}

It is just a function call to the "global" factory property with the string as parameter. And then for deserialization, you pass your own reader rather than having this done for you by the (serialization) format. (See also: https://pdvrieze.github.io/xmlutil/core/nl.adaptivity.xmlutil/-i-xml-streaming/index.html#323393628%2FFunctions%2F132463284).

Note that caching is enabled by default but is scoped on the format instance (don't recreate it for each (de)serialization for best speed).

@LogeswaranRamasamy
Copy link
Author

@pdvrieze I tried it out & could see some noticeable reductions in processing time in my end. Thanks!!!

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

2 participants