From 266dc922f16911f77ddb283b5aac4847b9d4d70c Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Mon, 18 Apr 2016 16:37:29 -0400 Subject: [PATCH] xml analysis: internalize strings. Stings are currently taking a major amount of memory. This patch reduces the memory usage by making the strings internal (cached) so duplicates are no longer copied in memory. Change-Id: Id686ea8c0648ddf2a7d041b6975ffbab6607167c Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/70908 Reviewed-by: Genevieve Bastien Tested-by: Genevieve Bastien Reviewed-by: Hudson CI --- .../xml/core/model/TmfXmlPatternSegmentBuilder.java | 6 +++--- .../xml/core/model/TmfXmlStateAttribute.java | 12 ++++++++---- .../xml/core/segment/TmfXmlPatternSegment.java | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlPatternSegmentBuilder.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlPatternSegmentBuilder.java index 7b6c177107..d04068c2cb 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlPatternSegmentBuilder.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlPatternSegmentBuilder.java @@ -146,7 +146,7 @@ public class TmfXmlPatternSegmentBuilder { */ private void setPatternSegmentContent(ITmfEvent event, ITmfTimestamp start, ITmfTimestamp end, Map fields, @Nullable TmfXmlScenarioInfo scenarioInfo) { for (TmfXmlPatternSegmentField field : fFields) { - fields.put(field.getName(), field.getValue(event, scenarioInfo)); + fields.put(field.getName().intern(), field.getValue(event, scenarioInfo)); } if (scenarioInfo != null) { addStoredFieldsContent(event, fields, scenarioInfo); @@ -169,7 +169,7 @@ public class TmfXmlPatternSegmentBuilder { for (Entry entry : ((XmlPatternStateProvider) fContainer).getStoredFields().entrySet()) { ITmfStateValue value = ((XmlPatternStateProvider) fContainer).getHistoryBuilder().getStoredFieldValue(fContainer, entry.getValue(), info, event); if (!value.isNull()) { - fields.put(entry.getValue(), value); + fields.put(entry.getValue().intern(), value); } } } @@ -338,7 +338,7 @@ public class TmfXmlPatternSegmentBuilder { } else { name.append(fSegmentNameAttribute); } - return name.toString(); + return name.toString().intern(); } } } diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java index 6e9e6caad9..bae5c4e1fa 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java @@ -94,15 +94,15 @@ public abstract class TmfXmlStateAttribute implements ITmfXmlStateAttribute { switch (attribute.getAttribute(TmfXmlStrings.TYPE)) { case TmfXmlStrings.TYPE_CONSTANT: fType = StateAttributeType.CONSTANT; - fName = fContainer.getAttributeValue(attribute.getAttribute(TmfXmlStrings.VALUE)); + fName = getAttributeName(attribute); break; case TmfXmlStrings.EVENT_FIELD: fType = StateAttributeType.EVENTFIELD; - fName = fContainer.getAttributeValue(attribute.getAttribute(TmfXmlStrings.VALUE)); + fName = getAttributeName(attribute); break; case TmfXmlStrings.TYPE_LOCATION: fType = StateAttributeType.LOCATION; - fName = fContainer.getAttributeValue(attribute.getAttribute(TmfXmlStrings.VALUE)); + fName = getAttributeName(attribute); break; case TmfXmlStrings.TYPE_QUERY: List<@Nullable Element> childElements = XmlUtils.getChildElements(attribute); @@ -118,7 +118,7 @@ public abstract class TmfXmlStateAttribute implements ITmfXmlStateAttribute { break; case TmfXmlStrings.TYPE_EVENT_NAME: fType = StateAttributeType.EVENTNAME; - fName = fContainer.getAttributeValue(attribute.getAttribute(TmfXmlStrings.VALUE)); + fName = getAttributeName(attribute); break; case TmfXmlStrings.NULL: fType = StateAttributeType.NONE; @@ -133,6 +133,10 @@ public abstract class TmfXmlStateAttribute implements ITmfXmlStateAttribute { } } + private String getAttributeName(Element attribute) { + return fContainer.getAttributeValue(attribute.getAttribute(TmfXmlStrings.VALUE)).intern(); + } + /** * @since 2.0 */ diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/segment/TmfXmlPatternSegment.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/segment/TmfXmlPatternSegment.java index b80f0095ff..f32406ab59 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/segment/TmfXmlPatternSegment.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/segment/TmfXmlPatternSegment.java @@ -185,7 +185,7 @@ public class TmfXmlPatternSegment implements ISegment { int length = in.readInt(); byte[] bytes = new byte[length]; in.read(bytes, 0, length); - String name = new String(bytes); + String name = new String(bytes).intern(); Byte type = in.readByte(); ITmfStateValue value; @@ -203,7 +203,7 @@ public class TmfXmlPatternSegment implements ISegment { length = in.readInt(); bytes = new byte[length]; in.read(bytes, 0, length); - value = TmfStateValue.newValueString(new String(bytes)); + value = TmfStateValue.newValueString(new String(bytes).intern()); break; default: throw new IOException("Read object failed : Invalid data"); //$NON-NLS-1$ -- 2.34.1