[jdom-interest] Re: Factories

Elliotte Rusty Harold elharo at metalab.unc.edu
Mon Mar 1 08:14:07 PST 2004


At 4:13 PM +0100 3/1/04, phil at triloggroup.com wrote:
>>>The cost of all inn-memory manipulation is trivial compared to the 
>>>cost of input and output (including parsing and serialization)<<<
The tests I sent to Jason this week end show that SAXBuilder is about 
25% faster with the uncheckedFactory. The bigger the document is, the 
higher the gain is (up to 40% for a middle sized document).

We're not talking about using it with a builder. That's fine because 
the parser is already checking well-formedness, and there's no need 
to duplicate the checks. The question is whether this should be 
available to create elements that have not been parsed.

For our own purposes, building an HTML DOM is ~300% faster with the 
factory (4 times faster!). Obviously, these numbers justify the use 
of the factory, especially when serving HTML pages on a web server.

Actually no, they don't. I suspect the real bottleneck on this system 
is not anywhere near the JDOM construction. A 300% speed-up in a part 
of the code that takes 0.1% of the time is irrelevant. I'd be very 
surprised in the bottleneck in the web app weren't somewhere else 
like network latency or database access. And even if it were in JDOM, 
there might be some way to create the documents that doesn't require 
an UnverifiedFactory.. Off the top of my head I can think of two. 
Prebuild most of the document, either clone or serialize and 
unserialize it, and then just make the modifications required for 
each request.

>>>There's simply no point to optimizing the speed of object creation 
>>>and manipulation<<<
Well, the numbers above contradict this assertion.

>>>It's certainly not worth doing at the cost of correctness<<
The code which uses this facility should effectively ensure the 
correctness by itself. For example, when you're deserializing an XMLS 
stream you encoded yourself, you're sure of the document validity and 
do not need any validation overhead.

Maybe you and the programmers you hire are that good. Personally I'm 
not, and I've never met anybody who is.


About making it private, I'm sure it can be used by other builders, 
beyond SAXBuilder. XMLS builder is an example, but why not a pull 
parser builder or other kind of builders? A factory should be public, 
and accessible by external code.

A StAX builder might be a reasonable project for a JDOM 1.1 if and 
when StAX seems significantly better than SAX. However this is all 
hypothetical. There are currently no non-SAX XML parsers written in 
Java which could reasonably be used for general purpose building.

-- 

   Elliotte Rusty Harold
   elharo at metalab.unc.edu
   Effective XML (Addison-Wesley, 2003)
   http://www.cafeconleche.org/books/effectivexml            
   http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA 



More information about the jdom-interest mailing list