users@jaxb.java.net

Re: Optimizing JAXB RI Marshal performance

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Fri, 21 Sep 2012 20:23:34 +0200

I think you have asked your question yourself.

The 27K is certainly an indication of a hefty object, but I wasn't sure
whether you were referring to the size of a Java serialization or the
one of the XML text. Marshalling to a StringWriter is bounded by the
underlying StringBuffer operation, which reallocates its buffer frequently,
doubling the size, and (in this case needlessly) synchronizes most
accesses. But all of this should not cause delays anywhere near to
what you have posted, not for 27K of XML text. You might save a
few milliseconds by calling the StringWriter constructor
with an initial buffer size. But the big delay is certainly not due to JAXB,
with the pojo being as simple as the one you've posted.

-W


On 21/09/2012, Farrukh Najmi <farrukh_at_wellfleetsoftware.com> wrote:
> Hi Wolfgang,
>
> Please see inline below (and thanks for your help)...
>
> On 09/21/2012 12:39 PM, Wolfgang Laun wrote:
>> Also, how many fields are there to be marshalled, in the POJO and any
>> contained objects?
>
> Please see a copy of the POJO XML here:
>
> http://www.wellfleetsoftware.com/files/tmp/big-auditable-event.xml
>
> There are many contained fields including collections that have a few
> hundred members.
>
> I noticed in debugger that if I do two back to back marshals of same
> object then second time is very fast.
> This made me realize that the POJO was created by hibernate with lazy
> init of collections whichh required db access the first time but not the
> second time.
>
> So perhaps this is not a JAXB issue after all?
>
>>
>> On 21/09/2012, Wolfgang Laun <wolfgang.laun_at_gmail.com> wrote:
>>> How big is the resulting XML?
>
> 27KB
>
>>> On 21/09/2012, Farrukh Najmi <farrukh_at_wellfleetsoftware.com> wrote:
>>>> (Resending with subject corrected... Please reply to this thread
>>>> instead
>>>> of previous one)
>>>>
>>>> Hi Guys,
>>>>
>>>> I am observing a 5 second delay in marshalling a POJO to XML using JAXB
>>>> / JAXB-RI 2.2.3.
>>>>
>>>> The size of the POJO is 27K (measured by writing to file). The
>>>> marshaling was to a StringWriter using code like this:
>>>>
>>>> JAXBElement elem = ...
>>>> if (elem != null) {
>>>> StringWriter sw = new StringWriter();
>>>> marshaller.marshal(elem, sw);
>>>> }
>>>>
>>>> This seems excessive a delay but I have nothing to compare it to. Any
>>>> thoughts on whether this seems reasonable?
>>>> Are there any tricks to speed this up? Thanks for your help.
>>>>
>>>> --
>>>> Regards,
>>>> Farrukh Najmi
>>>>
>>>> Web: http://www.wellfleetsoftware.com
>>>>
>>>>
>
>
> --
> Regards,
> Farrukh Najmi
>
> Web: http://www.wellfleetsoftware.com
>
>