simplexml
simplexml copied to clipboard
Use buffers to increase speed
I noticed that the XML Parser takes a lot of time when processing bit amounts of data. I noticed that you use ByteStreams but no buffers. Using buffers usually improves performance by a lot. Therefore it would be wise to use them here as well to increase speed
https://github.com/codemonstur/simplexml/blob/ad60080569b15a2ca41e8fa588d788a0805ebb50/src/main/java/xmlparser/XmlParser.java#L126-L128
This can be improved by using e.g. a BufferedReader
try (InputStreamReader streamReader = new InputStreamReader(stream, this.charset);
BufferedReader bufferedReader = new BufferedReader(streamReader)) {
return XmlReader.toXmlDom(bufferedReader, this.trimmer, this.escaper);
}
However, this cannot be just copied and pasted as the toXmlDom expects an InputStream
My primary concern with writing the library was to make it correct, simple and clean. Speed has always been a secondary concern. That said, I'd love to make it faster. My problem has been that I can't find a good benchmark project that I can use to compare simplexml against other libraries or to compare it against real world XML.
I'm hesitant to make changes to the code base based on guesses about what would make it faster. The BufferedReader thing I can add though. That isn't going to hurt :)
I've pushed a new version of the library. Mostly I added a BufferedInputStream where appropriate, and cleaned up some minor stuff. Without any benchmarks I won't be able to tell if anything is going faster or not.