Details
-
Improvement
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.8.2
-
None
-
Important
Description
When calling traceExit(object instance) the underlying code allocates a Message for the input object instance although the log level is not TRACE and there won't be any printing in the end.
With trivial objects is not a problem but using large lists or XML objects results in large memory allocation for nothing which goes to GC and performance impact.
Execution flow is like this:
@Override public <R> R traceExit(final R result) { return exit(FQCN, null, result); }
next exit calls:
protected <R> R exit(final String fqcn, final R result) { logIfEnabled(fqcn, Level.TRACE, EXIT_MARKER, exitMsg(null, result), null); return result; }
which calls exitMsg with the input parameter result:
protected Message exitMsg(final String format, final Object result) { if (result == null) { if (format == null) { return messageFactory.newMessage("Exit"); } return messageFactory.newMessage("Exit: " + format); } if (format == null) { return messageFactory.newMessage("Exit with(" + result + ')'); } return messageFactory.newMessage("Exit: " + format, result); }
As it can be seen the exitMsg() method is called and only later the logIfEnabled() is executed.
I assume a log level validation can be applied upfront so as exitMsg is not called for nothing.
Note: this is not the case for other flavors of traceExit which check the log level upfront.
Thank you