Type provider and big XML file

百般思念 提交于 2020-01-06 20:13:14

问题


I am wondering what are the good practices in using type provider in F#,

I have an XML file (25Mo+), I thought it will not be an issue but my Visual Studio is suffering a lot loll. What is usually the good practice, to define a complete template of the XML with the minimum of data and Load the content later ?

And if we load a big file with optional node, the type will be inferred by the most complete one ?

Thanks


回答1:


The XmlProvider type provider is based on XDocument (LINQ to XML), so it always needs to read the file into memory. However, there may be some additional overhead caused by the schema inference, which you can avoid. So, if LINQ to XML can read 25MB file (I'm not sure, try using XDocument.Load on the file), then you would be able to use the type provider.

Assuming big.xml is your big file, you can try deleting some of the elements from the file (so that all structure is there, but it is smaller) and creating small.xml. Then you can use:

type X = XmlProvider<"small.xml">
let data = X.Load("big.xml")

This will only run schema inference on the smaller file (which runs in background in Visual Studio) and then it attempts to read the bigger file using LINQ to XML. This just reads the file, so if LINQ to XML can read 25MB file, this will work.

Ideally, we would have some variation on the type provider that works over XmlReader or something like that - this could reuse some of F# Data infrastructure, but it would still be a lot of work (open an issue at F# Data is you're interested in contributing!)




回答2:


Yes, there are (hopefully temporarily) huge perf issues with XMLProvider. https://github.com/fsharp/FSharp.Data/issues/975

If someone would merge my PR of #983 or #976 they would be fixed. In a meanwhile you can fork and try a copy of my repo at https://github.com/Thorium/FSharp.Data



来源:https://stackoverflow.com/questions/37142356/type-provider-and-big-xml-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!