Skip to main content

FI Performance

3 replies [Last post]
gaydin
Offline
Joined: 2006-07-26
Points: 0

I've been using FI in some of my projects but the major bottleneck I see is the high decoding cost. In my experience decoding a fi document back to XML is much expensive than encoding an XML doc to fi.

Is this really the case, or am I doing something wrong?

Thanks
Galip.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sandoz
Offline
Joined: 2003-06-20
Points: 0

My guess is you are comparing the following two processes:

1) FI doc -> infoset -> XML doc

2) XML doc -> infoset -> FI doc

I have not actuallly measured such processes in total but have measured separately:

3) FI doc -> infoset

4) infoset -> XML doc

5) XML doc -> infoset

6) infoset -> FI doc

3 is faster 5 i.e. FI parsing is faster than XML parsing. 6 is comparable to or faster than 4 (in my experience XML can be serialized out very fast under certain circumstances, much faster than XML parsing).

So in this respect i would expect 1 to be faster than 2. BUT! it can depend on what APIs you are using (there could also be some bugs) so some more details on what you are doing would help me better to help you.

Paul.

gaydin
Offline
Joined: 2006-07-26
Points: 0

I am simply using the sample code presented on the FI project web site to do the XML<->FI conversions.

The methods I am using are here:

public void xml2fi_sax(String xmlPath, String fiPath) throws Exception {
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler",
saxDocumentSerializer);

fis = new FileInputStream(xmlPath);
fos = new FileOutputStream(fiPath);

saxDocumentSerializer.setOutputStream(fos);
saxParser.parse(new BufferedInputStream(fis), saxDocumentSerializer);

fis.close();
fos.close();
}

public void fi2xml_sax(String fiPath, String xmlPath) throws
Exception {
fis = new FileInputStream(fiPath);
fos = new FileOutputStream(xmlPath);

Transformer tx = TransformerFactory.newInstance().newTransformer();

tx.transform(new FastInfosetSource(fis), new StreamResult(fos));

fis.close();
fos.close();

}

What I need to find out is the 'fastest' way to do full document conversions, instead of serializations.

Thank you,
Galip.

sandoz
Offline
Joined: 2003-06-20
Points: 0

For parsing side as long as the XML and FI SAX parsers are reused things should be OK. Although you may want to see if:

saxDocumentSerializer.setOutputStream(
new BufferedOutputStream(fos));

makes any difference, it may not because the FI serializer does buffer a bit.

For the serializing side this code is functional but not optimal because it is not possible to resuse instances, the transformer can be expensive, and the FastInfosetSource/Result classes are designed for interoperation and not performance (see JavaDoc). Using a BufferedOutputStream would also be recommended.

The SAXTransformerFactory is probably more efficient and can be used directly with the FI SAXDocumentParser:

// Reuse the factory and parser for multiple handlers
SAXTransformerFactory stf =
SAXTransformerFactory.newInstance();
SAXDocumentParser fisdp = ...

TransformerHandler handler = stf.newTransformerHandler();
handler.setResult(new StreamResult(
new BufferedOutputStream(fos)));
fisdp.setContentHandler(handler);
fisdp.setLexicalHandler(handler);
fisdp.parse(fis);

Hope this helps,
Paul.