Modify

Opened 12 years ago

Closed 12 years ago

Last modified 10 years ago

#7386 closed enhancement (fixed)

Improve preferences dialog startup time

Reported by: Don-vip Owned by: team
Priority: normal Milestone:
Component: Core Version: latest
Keywords: Cc:

Description

As JOSM grows, I noticed the preferences dialog takes more and more time to load.
Indeed, the build() method takes, without any plugin, more than 500ms, I think we can do better.

I've measured the time spent in the dialog construction to find the slowest preferences tabs (this is the time spent in addGui()):

org.openstreetmap.josm.gui.preferences.ShortcutPreference -> 115 ms
org.openstreetmap.josm.gui.preferences.ServerAccessPreference -> 56 ms
org.openstreetmap.josm.gui.preferences.ImageryPreference -> 51 ms
org.openstreetmap.josm.gui.preferences.LanguagePreference -> 45 ms
org.openstreetmap.josm.gui.preferences.MapPaintPreference -> 41 ms
org.openstreetmap.josm.gui.preferences.DrawingPreference -> 24 ms
org.openstreetmap.josm.gui.preferences.ColorPreference -> 22 ms
org.openstreetmap.josm.gui.preferences.advanced.AdvancedPreference -> 18 ms
org.openstreetmap.josm.gui.preferences.ValidatorPreference -> 14 ms
org.openstreetmap.josm.gui.preferences.PluginPreference -> 14 ms
org.openstreetmap.josm.gui.preferences.TaggingPresetPreference -> 11 ms
org.openstreetmap.josm.gui.preferences.ToolbarPreferences$Settings -> 10 ms
org.openstreetmap.josm.gui.preferences.BackupPreference -> 9 ms
org.openstreetmap.josm.gui.preferences.RemoteControlPreference -> 7 ms
org.openstreetmap.josm.gui.preferences.LafPreference -> 6 ms
org.openstreetmap.josm.gui.preferences.ProjectionPreference -> 3 ms
org.openstreetmap.josm.gui.preferences.AudioPreference -> 1 ms

Attachments (0)

Change History (24)

comment:1 by bastiK, 12 years ago

Maybe we can delay the building of the tabs till they are selected.

in reply to:  1 ; comment:3 by Don-vip, 12 years ago

Replying to bastiK:

Maybe we can delay the building of the tabs till they are selected.

I tried, but this requires to change PreferenceSetting interface, as we need to know the tab icon and tooltip before building the GUI. This would require a change in all the plugins that use preferences, is it acceptable ?

In the meantime we can improve our own tabs. For example I found why ShortutPreference is so slow on the first time, it is due to this piece of code in PrefJPanel:

    // A list of keys to present the user. Sadly this really is a list of keys Java knows about,
    // not a list of real physical keys. If someone knows how to get that list?
    private static Map<Integer, String> keyList = setKeyList();
    
    private static Map<Integer, String> setKeyList() {
        Map<Integer, String> list = new LinkedHashMap<Integer, String>();
        // I hate this, but I found no alternative...
        for (int i = 0; i < 65534; i++) {
            String s = KeyEvent.getKeyText(i);
            if (s != null && s.length() > 0 && !s.contains("Unknown")) {
                list.put(Integer.valueOf(i), s);
                //System.out.println(i+": "+s);
            }
        }
        list.put(Integer.valueOf(-1), "");
        return list;
    }
Last edited 10 years ago by Don-vip (previous) (diff)

in reply to:  3 comment:4 by Don-vip, 12 years ago

By the way this doesn't work with a non English locale:

            if (s != null && s.length() > 0 && !s.contains("Unknown")) {

"Unknown" is translated by Java.

comment:5 by Don-vip, 12 years ago

In 4929/josm:

see #7386 - Do not list unknown keyCodes when using a non-English locale

comment:6 by stoecker, 12 years ago

Searching from 0 to 1000, 61000 to 61999 and 65000 to 65534 (65534 should be included) should reduce sorting space a lot.

comment:8 by Don-vip, 12 years ago

In 4930/josm:

see #7386 - Speed up keyCodes retrieving (from ~50ms to 1ms only)

comment:9 by stoecker, 12 years ago

Nice.

in reply to:  3 comment:10 by bastiK, 12 years ago

Replying to Don-vip:

Replying to bastiK:

Maybe we can delay the building of the tabs till they are selected.

I tried, but this requires to change PreferenceSetting interface, as we need to know the tab icon and tooltip before building the GUI. This would require a change in all the plugins that use preferences, is it acceptable ?

I'd say it's worth the trouble, preference start is definitely too slow at the moment.

comment:11 by Don-vip, 12 years ago

In 4931/josm:

see #7386 - Speed up languages JComboBox initialization (from ~40ms to 5ms only)

comment:12 by stoecker, 12 years ago

The next tested is a cleanup release anyway (dropped all deprecation and reworking shortcuts and a lot of other old stuff). So go on and design a better interface which can speedup the preference loading before we do the release.

When doing so: It should be possible to call preferences dialog with a preferences section and also a sub-tab preselected. I think first was implemented by Frederik, don't know about second.

in reply to:  12 comment:13 by Don-vip, 12 years ago

Replying to stoecker:

The next tested is a cleanup release anyway (dropped all deprecation and reworking shortcuts and a lot of other old stuff). So go on and design a better interface which can speedup the preference loading before we do the release.

This was more complex than I thought, but it's done :) It's such a pleasure to view preferences dialog as soon as you press F12 :)

When doing so: It should be possible to call preferences dialog with a preferences section and also a sub-tab preselected. I think first was implemented by Frederik, don't know about second.

Yes, I've seen that, it's used in color dialog to launch preferences dialog with "Display" tab and its second sub-tab preselected. It works :)

comment:14 by Don-vip, 12 years ago

Resolution: fixed
Status: newclosed

In 4968/josm:

fix #7386 - Major rework of preferences GUI settings in order to speed up preferences dialog startup time. The building of each preferences tab is delayed until this tab is selected. Plugins that use preferences will need to make some (minor) changes.

comment:15 by Don-vip, 12 years ago

In 4969/josm:

fix #7386 for good - Don't know why these files have been skipped from previous commit.

comment:16 by stoecker, 12 years ago

Some work to be done. JOSM produces a lot of NullPointer exceptions when clicking ok without viewing tabs (plugins, serverprefs, validator, ...).

comment:17 by stoecker, 12 years ago

Resolution: fixed
Status: closedreopened

comment:18 by stoecker, 12 years ago

Sadly this killed my toolbar prefs.

comment:19 by Don-vip, 12 years ago

In 4970/josm:

see #7386 - call ok() only on initialized settings + fix NPE in plugins management

in reply to:  18 ; comment:20 by Don-vip, 12 years ago

Replying to stoecker:

Sadly this killed my toolbar prefs.

Sorry for that :( Does r4970 fix it ?

in reply to:  20 comment:21 by stoecker, 12 years ago

Resolution: fixed
Status: reopenedclosed

Replying to Don-vip:

Sorry for that :( Does r4970 fix it ?

I think so.

comment:22 by Don-vip, 12 years ago

Ticket #6392 has been marked as a duplicate of this ticket.

comment:23 by simon04, 12 years ago

What about using a singleton instance of PreferenceDialog as further enhancement?

comment:24 by akks, 12 years ago

I am not sure it is worth it. PreferenceDialog itself is not heavy. Currently almost all preferences and cache reading, layout, and more other work is done when opening tab.

If it is done only once, there can be problems with reflecting preferences changes.

Listeners and major rework of tabs will be needed, and in the end almost the same amount of work will be done when preference tab open.

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.