Sven,
        We were seeing a similar problem when compiling hundreds of xsltc 
transforms.
We saw increasing memory consumption and so blamed compiling and loading lots 
of transform classes.
We felt that this theory was confirmed when we found that running under Java 
1.8 removed this problem.
Because java 1.8 added garbage collection of classes.
So, if you are not running Java 1.8, consider trying it.

Phil

-----Original Message-----
From: Sven Richter [mailto:[email protected]] 
Sent: Wednesday, March 01, 2017 4:28 AM
To: [email protected]
Subject: java xml TransformerFactory.newTransformer getting slower during tests

I have a problem where I do not know what the root cause actually is.
I also asked already in different places without getting an answer.

I create an instance of javax.xml.transform.TransformerFactory and directly 
afterwards I parse a xsltSource:


protected synchronized Transformer getTransformer(Source xsltSource)
    throws TransformerConfigurationException {

    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer(xsltSource);
    return transformer;
}

I am using the com.sun.org.apache.xalan.internal.xsltc.trax.Trans
formerFactoryImpl com.sun.org.apache.xalan.internal.xsltc.trax.Trans
formerImpl classes.
Which are the ones provided by the JDK.


Now I have a test that is part of the test suite. When I run that test 
standalone the code above takes around 1ms constantly.

When I run that test as part of my test suite it takes longer. This happens as 
well in eclipse as with gradle. The duration rises linear with the amount of 
tests that run before.

Its orders of magnitudes slower, like 10 - 1000 times, depending on how much 
tests run before that specific test.

Using a cached instance of the TransfomerFactory will cut the time the test 
takes in half. But the symptom remains the same.
I have been profiling it, but dont see anything suspicious, except the the test 
takes longer.

My first assumption was it had directly to do with the number of loaded 
classes, which it does not. Loading classes arbitrarily does not change the 
time the test needs.

Next I added the saxon parser and specifically used that one, but the symptom 
remains the same.

Also I figured out I have the same problem with this line of code:

SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();

Any ideas what might be the cause here?

Thanks,
Sven

Reply via email to