Modify

Opened 8 years ago

Closed 7 years ago

#13309 closed enhancement (fixed)

Caching and notifying preferences

Reported by: michael2402 Owned by: michael2402
Priority: normal Milestone: 17.04
Component: Core Version:
Keywords: gsoc-core Cc: Don-vip, bastiK, stoecker

Description (last modified by michael2402)

Currently, there are many MapFrame.repaint() calls whenever properties change.

Part of this is because colors and other values are cached by each component seperately.

I added a new infrastructure that allows you to get a property and easily cache that result.

To get a property use:

new IntegerProperty("my.property", "123").get()

To cache the result, use:

prop = new IntegerProperty("my.property", "123").cached(); // registers 123 as default value
prop.get(); // lazy get and convert to int
prop.get(); // get cached integer object

I added a new preference listener that listens to changes of one specific key to make this efficient.

Attachments (5)

patch-preferences-listenable-2.patch (86.8 KB ) - added by michael2402 8 years ago.
patch-fix-13309.patch (86.8 KB ) - added by michael2402 8 years ago.
patch-latlon-generic.patch (45.4 KB ) - added by michael2402 8 years ago.
patch-fix-13309-2.patch (14.2 KB ) - added by michael2402 8 years ago.
patch-fix-13309-2.2.patch (14.2 KB ) - added by michael2402 8 years ago.

Download all attachments as: .zip

Change History (43)

by michael2402, 8 years ago

comment:1 by simon04, 8 years ago

Description: modified (diff)

comment:2 by Don-vip, 8 years ago

Patch does not apply anymore, can you please update it?

by michael2402, 8 years ago

Attachment: patch-fix-13309.patch added

comment:3 by Don-vip, 8 years ago

    public static class ValueChangeEvent<T> {
        private final PreferenceChangeEvent base;

        private final AbstractProperty<T> source;

        ValueChangeEvent(PreferenceChangeEvent base, AbstractProperty<T> source) {
            this.base = base;
            this.source = source;
        }

base is not used?

comment:4 by Don-vip, 8 years ago

Why is the timeout commented in JOSMTestRules?

           //  statement = new FailOnTimeoutStatement(statement, timeout);

comment:5 by Don-vip, 8 years ago

In 10824/josm:

see #13309 - Caching and notifying preferences (patch by michael2402) - gsoc-core

comment:6 by michael2402, 8 years ago

Thanks for finding that timeout. No, it should not be commented. I did this for debugging.

comment:7 by Don-vip, 8 years ago

Resolution: fixed
Status: newclosed

ok this is fixed, I didn't apply this part.

comment:8 by Don-vip, 8 years ago

Resolution: fixed
Status: closedreopened
Summary: [Patch] Caching and notifying preferencesCaching and notifying preferences

this is not, this patch cause 74 unit test failures: jenkins/job/JOSM/1725/testReport/

comment:9 by Don-vip, 8 years ago

Owner: changed from team to michael2402
Status: reopenednew

comment:10 by Don-vip, 8 years ago

In 10839/josm:

see #13309 - remove deprecated color stuff not used outside of JOSM

comment:11 by Don-vip, 8 years ago

In 10853/josm:

see #13309 - fix most of deprecation warnings

comment:12 by Don-vip, 8 years ago

it seems the exception causing all these test failures is

java.lang.NullPointerException
	at org.openstreetmap.josm.data.preferences.AbstractToStringProperty.getAsString(AbstractToStringProperty.java:131)
	at org.openstreetmap.josm.data.preferences.AbstractToStringProperty.get(AbstractToStringProperty.java:92)
	at org.openstreetmap.josm.data.preferences.BooleanProperty.get(BooleanProperty.java:21)
	at org.openstreetmap.josm.tools.date.DateUtils.getDateTimeFormat(DateUtils.java:311)
	at org.openstreetmap.josm.gui.dialogs.NotesDialog$NoteRenderer.<init>(NotesDialog.java:209)
	at org.openstreetmap.josm.gui.dialogs.NotesDialog$NoteRenderer.<init>(NotesDialog.java:206)
	at org.openstreetmap.josm.gui.dialogs.NotesDialog.buildDialog(NotesDialog.java:85)
	at org.openstreetmap.josm.gui.dialogs.NotesDialog.<init>(NotesDialog.java:78)
	at org.openstreetmap.josm.gui.MapFrame.<init>(MapFrame.java:264)
	at org.openstreetmap.josm.gui.MainPanel.createNewMapFrame(MainPanel.java:88)
	at org.openstreetmap.josm.gui.MainPanel.updateContent(MainPanel.java:63)
	at org.openstreetmap.josm.gui.MainPanel$1.beforeFirstLayerAdded(MainPanel.java:157)
	at org.openstreetmap.josm.gui.layer.MainLayerManager.realAddLayer(MainLayerManager.java:264)
	at org.openstreetmap.josm.gui.layer.LayerManager.lambda$addLayer$0(LayerManager.java:180)
	at org.openstreetmap.josm.gui.util.GuiHelper.runInEDTAndWaitWithException(GuiHelper.java:138)
	at org.openstreetmap.josm.gui.layer.LayerManager.addLayer(LayerManager.java:180)
	at org.openstreetmap.josm.JOSMFixture.setupGUI(JOSMFixture.java:154)
	at org.openstreetmap.josm.JOSMFixture.access$000(JOSMFixture.java:28)
	at org.openstreetmap.josm.JOSMFixture$1.run(JOSMFixture.java:128)

comment:13 by michael2402, 8 years ago

The problem is that some class loads DateUtils before Main.pref is instantiated.

I suggest fixing this and adding a dependency on preferences for that test. I'll find the test that causes this and post a patch for it.

An alternative to make our life easier would be to make Main.pref a final field instantiated with an empty instance. We can then simply load it during program startup. This would also make early application startup much easier, since we currently have many classes that may only be loaded after Main.pref is set. We should make those classes listen to preferences updates though, but this is why I created this patch.

comment:14 by michael2402, 8 years ago

Description: modified (diff)

by michael2402, 8 years ago

Attachment: patch-latlon-generic.patch added

by michael2402, 8 years ago

Attachment: patch-fix-13309-2.patch added

by michael2402, 8 years ago

Attachment: patch-fix-13309-2.2.patch added

comment:15 by michael2402, 8 years ago

Summary: Caching and notifying preferences[Patch] Caching and notifying preferences

Please ignore patch-latlon-generic.patch​ and patch-fix-13309-2.2.patch​. This happens if you have 4 track windows open because it has a load time of 2 Minutes (if it loads)

I attached patch-fix-13309-2.patch​ to address the issue. It makes the pref field final. That field was only changed in tests and should never be changed while JOSM is running, so it should not be a problem.

comment:16 by Don-vip, 8 years ago

Resolution: fixed
Status: newclosed

In 10876/josm:

fix #13309 - fix unit tests (patch by michael2402) - gsoc-core

comment:17 by Don-vip, 8 years ago

Resolution: fixed
Status: closedreopened

Much better, still 9 tests to fix:

  1. org.openstreetmap.josm.gui.dialogs.InspectPrimitiveDialogTest.testBuildMapPaintText
  2. org.openstreetmap.josm.data.PreferencesTest.testColorNameAlpha
  3. org.openstreetmap.josm.data.PreferencesTest.testColorAlpha
  4. org.openstreetmap.josm.gui.JosmUserIdentityManagerTest.test_SingletonAccess
  5. org.openstreetmap.josm.gui.JosmUserIdentityManagerTest.userNameChanged
  6. org.openstreetmap.josm.gui.JosmUserIdentityManagerTest.apiUrlChanged
  7. org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSParserTest.testColorNameTicket9191
  8. org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSParserTest.testColorNameTicket9191Alpha
  9. org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandlerTest.testHandleException

in reply to:  15 comment:18 by Don-vip, 8 years ago

Replying to michael2402:

because it has a load time of 2 Minutes (if it loads)

website was targeted by what seems to be a DDoS, I found a solution, it is now much faster.

comment:19 by Don-vip, 8 years ago

Deprecation warnings must also be fixed:

PropertiesCellRenderer.java:37, Java Compiler (javac), Priority: Normale
getColor(String,Color) in Preferences has been deprecated

PropertiesCellRenderer.java:38, Java Compiler (javac), Priority: Normale
getColor(String,Color) in Preferences has been deprecated

PropertiesCellRenderer.java:41, Java Compiler (javac), Priority: Normale
getColor(String,Color) in Preferences has been deprecated

PropertiesCellRenderer.java:42, Java Compiler (javac), Priority: Normale
getColor(String,Color) in Preferences has been deprecated

MapCSSParser.java:2025, Java Compiler (javac), Priority: Normale
getColor(String,Color) in Preferences has been deprecated
MapView.java:869, Java Compiler (javac), Priority: Normale
isChanged() in Layer has been deprecated

AbstractTileSourceLayer.java:1853, Java Compiler (javac), Priority: Normale
isChanged() in Layer has been deprecated

GpxLayer.java:259, Java Compiler (javac), Priority: Normale
isChanged() in Layer has been deprecated

OsmDataLayer.java:896, Java Compiler (javac), Priority: Normale
isChanged() in Layer has been deprecated

ValidatorLayer.java:126, Java Compiler (javac), Priority: Normale
isChanged() in Layer has been deprecated
Last edited 8 years ago by Don-vip (previous) (diff)

comment:20 by Don-vip, 8 years ago

Summary: [Patch] Caching and notifying preferencesCaching and notifying preferences

comment:21 by michael2402, 7 years ago

In 10920/josm:

See #13309: Do not add 'color.' prefix twice in getColor()

comment:22 by michael2402, 7 years ago

In 10922/josm:

See #13309: Make PreferencesTest compile again.

comment:23 by Don-vip, 7 years ago

Resolution: fixed
Status: reopenedclosed

comment:24 by Don-vip, 7 years ago

Resolution: fixed
Status: closedreopened

one remaining deprecation warning to fix in MapCSSParser.jj:

        { return Main.pref.getColor("mappaint." + (sheet == null ? "MapCSS" : sheet.title) + "." + pref, ColorHelper.html2color(t.image)); }

comment:25 by michael2402, 7 years ago

Milestone: 16.0816.09

I was working on that one already.

I have two options:

  1. Simply replace that call
  2. Use a color property as return value - that way, we can reload preferences easier

I'd like to apply Option 2 after the release

comment:26 by simon04, 7 years ago

Milestone: 16.0916.10

Milestone renamed

comment:27 by simon04, 7 years ago

Since recently, opening the preferences outputs the following warnings:

Last errors/warnings:
- W: Unable to get color from '' for color preference 'extrude.main.line'
- W: Unable to get color from '' for color preference 'improve.way.accuracy.helper.line'
- W: Unable to get color from '' for color preference 'make.parallel.helper.line'

comment:28 by simon04, 7 years ago

Milestone: 16.1016.11

comment:29 by michael2402, 7 years ago

In 11270/josm:

See #13309: Make download dialog use preferences interface.

comment:30 by Don-vip, 7 years ago

Milestone: 16.1116.12

Milestone renamed

comment:31 by Don-vip, 7 years ago

Milestone: 16.1217.01

comment:32 by Don-vip, 7 years ago

Milestone: 17.0117.02

comment:33 by Don-vip, 7 years ago

#14343#comment:10 must be addressed as well.

in reply to:  27 comment:34 by Klumbumbus, 7 years ago

Replying to simon04:

Since recently, opening the preferences outputs the following warnings:

Last errors/warnings:
- W: Unable to get color from '' for color preference 'extrude.main.line'
- W: Unable to get color from '' for color preference 'improve.way.accuracy.helper.line'
- W: Unable to get color from '' for color preference 'make.parallel.helper.line'

I think this was fixed in r11542

comment:35 by Don-vip, 7 years ago

Milestone: 17.0217.03

comment:36 by michael2402, 7 years ago

In 11758/josm:

See #13309: Use cached preferences for map drawing; align box text to full pixels if not rotated.

comment:37 by michael2402, 7 years ago

Milestone: 17.0317.04

comment:38 by Don-vip, 7 years ago

Resolution: fixed
Status: reopenedclosed

The warnings have been solved in r11623 and r11713.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain michael2402.
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.