Dominik Süß created FELIX-6664:
----------------------------------
Summary: Comment Removing on JSONSupport MemoryInefficient
Key: FELIX-6664
URL: https://issues.apache.org/jira/browse/FELIX-6664
Project: Felix
Issue Type: Improvement
Reporter: Dominik Süß
While using JSONSupport in Context of the Sling Featurelauncher we recently
stumbled over an OOM exception related to how JSONSupport handles removal of
comments:
{code}
java.lang.OutOfMemoryError: Java heap space
at java.base/java.util.Arrays.copyOfRange(Arrays.java:4030)
at java.base/java.lang.StringUTF16.newString(StringUTF16.java:1025)
at java.base/java.lang.StringBuilder.toString(StringBuilder.java:454)
at
org.apache.felix.cm.json.io.impl.JsonSupport.removeComments(JsonSupport.java:308)
at
org.apache.felix.cm.json.io.impl.JsonSupport.createCommentRemovingReader(JsonSupport.java:244)
at
org.apache.felix.cm.json.io.Configurations.jsonCommentAwareReader(Configurations.java:70)
at
org.apache.sling.feature.io.json.FeatureJSONReader.readFeature(FeatureJSONReader.java:676)
{code}
https://github.com/apache/felix-dev/blob/91432d1a3f08520d5eb75b5c8e3443bb75f7c467/cm.json/src/main/java/org/apache/felix/cm/json/io/impl/JsonSupport.java#L233-L257
The code does use a StringWriter to create a full String representation of the
featuremodel and then acts on that model. As this featuremodel can contain a
lot of metadata in comments those can get a significant size and when being
used in a resource constrained environment can lead to memory issues.
I prepared a patch that doesn't touch the removal logic but simply creates a
custom BufferedReader that performs the removal on read and therefore
eliminates the most prominent area for resource optimization.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)