Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary DocumentBuilderFactory Creation #182

Closed
tutufool opened this issue May 11, 2020 · 4 comments
Closed

Avoid unnecessary DocumentBuilderFactory Creation #182

tutufool opened this issue May 11, 2020 · 4 comments

Comments

@tutufool
Copy link

In DOMDifferenceEngine, we have:

    private DocumentBuilderFactory documentBuilderFactory =
        DocumentBuilderFactoryConfigurer.Default.configure(DocumentBuilderFactory.newInstance());

While if I provide my own DBF to DiffBuilder, above creation will be useless anyway due to override.

Since DOMDifferenceEngine is only used by DiffBuilder, I think it could be package private, and a constructor with DBF could be provided. (let DiffBuilder inject a DBF to it, either new or provided by caller).

Pretty much like the way to handle WhitespaceNormalizedSource.

I raise this issue because I observed some of my threads during LnP are running at below stack:

lang.Thread.State: RUNNABLE
at java.net.URLStreamHandler.parseURL(URLStreamHandler.java:255)
at java.net.URL.(URL.java:640)
at java.net.URL.(URL.java:508)
at sun.misc.URLClassPath$Loader.findResource(URLClassPath.java:701)
at sun.misc.URLClassPath.findResource(URLClassPath.java:225)
at java.net.URLClassLoader$2.run(URLClassLoader.java:572)
at java.net.URLClassLoader$2.run(URLClassLoader.java:570)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findResource(URLClassLoader.java:569)
at org.springframework.boot.loader.LaunchedURLClassLoader.findResource(LaunchedURLClassLoader.java:53)
at java.lang.ClassLoader.getResource(ClassLoader.java:1090)
at java.net.URLClassLoader.getResourceAsStream(URLClassLoader.java:233)
at org.apache.xerces.parsers.SecuritySupport$6.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.xerces.parsers.SecuritySupport.getResourceAsStream(Unknown Source)
at org.apache.xerces.parsers.ObjectFactory.findJarServiceProvider(Unknown Source)
at org.apache.xerces.parsers.ObjectFactory.createObject(Unknown Source)
at org.apache.xerces.parsers.ObjectFactory.createObject(Unknown Source)
at org.apache.xerces.parsers.DOMParser.(Unknown Source)
at org.apache.xerces.parsers.DOMParser.(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setFeature(Unknown Source)

Which indicate DBF's creation is a heavy operation.
(I already have my own thread-local bases DBF passed into DiffBuilder)

Thanks in advance for looking into it.

Leon

@bodewig bodewig added this to the 2.7.0 milestone May 11, 2020
@bodewig
Copy link
Member

bodewig commented May 11, 2020

DOMDifferenceEngine and DiffBuilder live in separate packages, so package private is not an option. To me the builder API has always been an alternative API to creating DOMDifferenceEngine directly so it has to stay public anyway.

Back when I added setDocumentFactory I should have chosen a new constructor instead, I don't recall why I opted for the setter.

@bodewig
Copy link
Member

bodewig commented May 11, 2020

I've changed the code to use a separate constructor now.

@tutufool
Copy link
Author

Cool, thanks for the super fast fix

@bodewig
Copy link
Member

bodewig commented May 12, 2020

2.7.0 has just been released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants