Modify

#23097 closed defect (fixed)

[PATCH] Significantly reduce allocations during startup in XmlObjectParser and PluginListParser

Reported by: taylor.smock Owned by: team
Priority: normal Milestone: 23.08
Component: Core Version:
Keywords: performance startup Cc:

Description

With the Name Suggestion Index preset added to JOSM, the following methods are relatively expensive during startup (mem old -> mem new, cpu old -> cpu new):

  • XmlObjectParser$Entry.getField (124 MB -> 8.1 MB, 501ms -> 99ms)
  • XmlObjectParser$Entry.getMethod (126 MB -> 452 kB, 292ms -> 45ms)

The gains are almost entirely from getting rid of copy calls to Method and Field (done when calling Class.getMethods() and Class.getFields()). There are further gains in JVM methods (like GC), but those can be a bit ticklish to profile correctly. It does look like a 20% improvement there though (32,653ms -> 26,075ms).

Note: I'm also including a change in PluginListParser to avoid compiling a pattern over and over again. That reduces the cost of PluginListParser.parse from 25.5 mb to 12.1 mb and 217ms to 162ms. Most of the remaining cost is stuff we cannot do anything about.

Additional note: The PluginListParser numbers included the cost of interning the strings. I ended up removing that since code analysis indicated that the strings were not kept long-term.

Attachments (1)

23097.patch (6.3 KB ) - added by taylor.smock 16 months ago.

Download all attachments as: .zip

Change History (3)

by taylor.smock, 16 months ago

Attachment: 23097.patch added

comment:1 by taylor.smock, 16 months ago

I might want to add the following to the patch:

  • src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java b/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java
    a b  
    1313import java.util.HashMap;
    1414import java.util.List;
    1515import java.util.Map;
     16import java.util.regex.Matcher;
     17import java.util.regex.Pattern;
    1618
    1719import org.openstreetmap.josm.data.Preferences;
    1820import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     
    8284    }
    8385
    8486    private static File[] listFiles(File pluginsDirectory, final String regex) {
    85         return pluginsDirectory.listFiles((FilenameFilter) (dir, name) -> name.matches(regex));
     87        final Matcher matcher = Pattern.compile(regex).matcher("");
     88        return pluginsDirectory.listFiles((dir, name) -> matcher.reset(name).matches());
    8689    }
    8790
    8891    protected void scanSiteCacheFiles(ProgressMonitor monitor, File pluginsDirectory) {

This removes 7.2 MB of allocations if all plugins have been downloaded.

comment:2 by taylor.smock, 16 months ago

Resolution: fixed
Status: newclosed

In 18796/josm:

Fix #23097: Significantly reduce allocations during startup in XmlObjectParser, PluginListParser, and ReadLocalPluginInformationTask

With the Name Suggestion Index preset added to JOSM, the following methods are
relatively expensive during startup (mem old -> mem new, cpu old -> cpu new):

  • XmlObjectParser$Entry.getField (124 MB -> 8.1 MB, 501ms -> 99ms)
  • XmlObjectParser$Entry.getMethod (126 MB -> 452 kB, 292ms -> 45ms)

The gains are almost entirely from getting rid of copy calls to Method and Field
(done when calling Class.getMethods() and Class.getFields()). There are
further gains in JVM methods (like GC), but those can be a bit ticklish to
profile correctly. It does look like a 20% improvement there though
(32,653ms -> 26,075ms).

This additionally reduces pattern compilation from PluginListParser.parse and
ReadLocalPluginInformationTask.listFiles.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.