Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

performance problem in Loader.reportUnexpectedChildElement #286

@glassfishrobot

Description

@glassfishrobot

By profiling my application I found out a performance problem in the unmarshal
code. My test code parses a document 10 times.
The Unmarshaller.unmarshal(File) calls take 1484 ms while 1000 of them are spent
in the Loader.reportUnexpectedChildElement.

This is because the error message is formatted (MessageFormat.format) even
thought it will never be used because the error messages are not reported to the
user. Also you use the static call to MessageFormat.format that creates the
MessageFormat in every call.

By caching the MessageFormat object (using the code sample below) the
performance is much better (600ms).

private final ThreadLocal format = new ThreadLocal();
public String format( Object... args )

{ if( format.get() == null ) format.set(new MessageFormat(rb.getString(name()))); return format.get().format( args ); }

but it could be even better if you could avoid the message construction if there
is no error handler registered (the default option).

Environment

Operating System: All
Platform: All

Affected Versions

[2.0.4]

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions