-
Notifications
You must be signed in to change notification settings - Fork 407
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
Enhance performance of AbstractPatternJsonProvider #688
Conversation
- PatternLayoutBase creates a new StringBuilder for every event it must serialize causing garbage and unnecessary pressure on the GC. Try to reuse a StringBuilder per thread. - Filtering of empty fields is getting values multiple times from the event which becomes expensive when the value is computed by a PatternLayout. Use Jackson's FilteringJsonGenerator instead. - Make use of the most appropriate JsonGenerator#write() method instead of using writeObject() for "simple" value types. Using writeObject() delegates to the underlying ObjectCode which is slower and produces lot more garbage. - Refactor the code to make it easier to read and understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the existing unit tests provide sufficient test coverage to ensure these changes did not change the generated JSON?
src/main/java/net/logstash/logback/composite/JsonWritingUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/net/logstash/logback/pattern/AbstractJsonPatternParser.java
Show resolved
Hide resolved
src/main/java/net/logstash/logback/pattern/AbstractJsonPatternParser.java
Outdated
Show resolved
Hide resolved
src/main/java/net/logstash/logback/pattern/AbstractJsonPatternParser.java
Outdated
Show resolved
Hide resolved
They seem to have good coverage already... Do you have additional scenarios in mind? |
No. I haven't looked at them. I just wanted to confirm. I trust your judgement. |
DelegatingNodeWriter is private and used only by OmitEmptyFieldWriter. Suppress the class and move the delegate field directly into the sub-class.
…s instead of logging an ERROR status AbstractJsonPatternParser now throws a JsonPatternException in case of invalid pattern. It is up to the AbstractPatternLayoutJsonProvider to catch the exception, log an error status and decide how it should behave. Invalid PatternLayout formats are now detected and throw a JsonPatternException as well. Detection is done by configuring the PatternLayout instances with a custom Logback context that throws an exception when an ERROR status is logged. The former implementation used to ignore fields with an invalid pattern layout while keeping the other. This results in a partial JSON output with only the valid fields. This behaviour is now changed and the provider reverts to producing nothing in case of bad configuration. These changes address issue #686.
… patterns instead of logging an ERROR status" This reverts commit 414f482. This changes will be committed in a separate branch.
I'm done with this PR. |
This PR addresses multiple performance issues of the AbstractJsonPatternParser.
JsonGenerator#write()
method instead of usingwriteObject()
for "simple" value types. UsingwriteObject()
delegates to the underlying ObjectCodec which is slower and produces lot more garbage.Benchmarks show that these changes make the AbstractPatternJsonProvider 4 times faster than LLE 6.6 and more importantly, it does not produce garbage anymore.