Bug 570962 - [performance] ResourceStateFactory: avoid string concatenation
Summary: [performance] ResourceStateFactory: avoid string concatenation
Status: RESOLVED FIXED
Alias: None
Product: EGit
Classification: Technology
Component: UI (show other bugs)
Version: 5.10   Edit
Hardware: All All
: P3 trivial (vote)
Target Milestone: 5.11   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-05 07:23 EST by Jörg Kubitz CLA
Modified: 2021-02-05 15:30 EST (History)
1 user (show)

See Also:


Attachments
Screenshot of JDK Mission Control showing Stacktrace (88.50 KB, image/png)
2021-02-05 07:27 EST, Jörg Kubitz CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jörg Kubitz CLA 2021-02-05 07:23:22 EST
ResourceStateFactory uses string concatenation which results in unneeded memory allocation.
During a refresh of a big workspace with ~ 100_000 file this showed up as a memory allocation hot spot.
No measurement in time units could be done since it is only affects garbage collection time. However JDK Mission Control stated that this single line allocated (i.e. wasted) ~ 500 MB.

Proposed improvement would eliminate that memory allocation at all:
https://git.eclipse.org/r/c/egit/egit/+/175831

I found no other places in the egit source where the same optimisation could be applied too.
Comment 1 Jörg Kubitz CLA 2021-02-05 07:27:31 EST
Created attachment 285455 [details]
Screenshot of JDK Mission Control showing Stacktrace
Comment 2 Jörg Kubitz CLA 2021-02-05 07:33:40 EST
callstack of top byte[] allocations by JDK MC was:

byte[] java.util.Arrays.copyOfRange(byte[], int, int)	159
   String java.lang.StringLatin1.newString(byte[], int, int)	159
      String java.lang.StringBuilder.toString()	98
         boolean org.eclipse.egit.ui.internal.resources.ResourceStateFactory.containsPrefixPath(Set, String)	71
            IResourceState org.eclipse.egit.ui.internal.resources.ResourceStateFactory.extractContainerProperties(IndexDiffData, String, ResourceStateFactory$FileSystemItem)	71
         IPath org.eclipse.core.internal.watson.ElementTreeIterator.requestPath()	19
         String java.util.regex.Matcher.replaceAll(String)	4
         PDEClasspathContainer$Rule org.eclipse.pde.internal.core.RequiredPluginsClasspathContainer.getRule(StateHelper, BundleDescription, ExportPackageDescription)	2
         String org.eclipse.jface.viewers.StyledString.getString()	1
         String org.eclipse.osgi.util.NLS.internalBind(String, Object[], String, String)	1
      String java.lang.String.substring(int, int)	61
void java.lang.AbstractStringBuilder.<init>(int)	92
   void java.lang.StringBuilder.<init>(String)	64
      boolean org.eclipse.egit.ui.internal.resources.ResourceStateFactory.containsPrefixPath(Set, String)	62
         IResourceState org.eclipse.egit.ui.internal.resources.ResourceStateFactory.extractContainerProperties(IndexDiffData, String, ResourceStateFactory$FileSystemItem)	61
            IResourceState org.eclipse.egit.ui.internal.resources.ResourceStateFactory.get(IndexDiffData, ResourceStateFactory$FileSystemItem)	61
               IResourceState org.eclipse.egit.ui.internal.resources.ResourceStateFactory.get(IndexDiffData, IResource)	61
                  void org.eclipse.egit.ui.internal.decorators.DecoratableResourceAdapter.<init>(IndexDiffData, IResource)	61
                     void org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator.decorateResource(IResource, IDecoration)	61
                        void org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator.decorate(Object, IDecoration)	61
Comment 4 Thomas Wolf CLA 2021-02-05 15:30:55 EST
Thanks, Jörg!