Modify

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#6421 closed enhancement (invalid)

[Patch] Reduce memory footprint in Node and WayPoint

Reported by: anonymous Owned by: team
Priority: normal Milestone:
Component: Core Version: latest
Keywords: Cc:

Description

The attached patch reduces the memory footprint of the Node and WayPoint classes. This is relevant, because JOSM internally creates a lot of Node instances (in particular in large datasets) and a lot of WayPoints, if GPS-Data is downloaded from the OSM server.

The patch mainly:

  • makes CachedLatLon obsolete. Major drawback of current CachedLatLon: each instance keeps a reference to the current global projection
  • inlines the lat/lon coordinates and the cached, projected east/north coordinates in the classes Node and WayPoint
  • properly reprojects Nodes and WayPoints, when the projection is changed

See this branch with one combined commit on GitHub, or this brach with individual smaller commits.

Attached a patch against JOSM 4114, formatted using git format-patch. If applied in Eclipse, you'll have to manually merge the very last entry. Just accept the update to Main.setProjection(new Epsg4326()); and ignore the rest.

Attachments (3)

0001-Combined-patch-for-reducing-memory-footprint-in-the-.patch (113.0 KB ) - added by anonymous 14 years ago.
Patch
0001-Combined-patch-for-reducing-memory-footprint-in-the-.2.patch (112.7 KB ) - added by anonymous 14 years ago.
Updated patch (forgot to remove one premature optimization in NodeData)
0001-Combined-commits-from-cached-lat-lon-patch-against-J.patch (114.3 KB ) - added by anonymous 14 years ago.
Updated patch against JOSM 4115, includes suggestions from this ticket

Download all attachments as: .zip

Change History (23)

comment:1 by anonymous, 14 years ago

Caveat: if applied, this patch will probably break some plugins.

Leave a comment if you need help on checking and fixing them.

comment:2 by stoecker, 14 years ago

Looks good on first view.

Now only proper handling of projections and projection changes for imagery layers is missing.

comment:3 by jttt, 14 years ago

I think it's a bit error-prone. If Node is not part of the Dataset and Dataset part of OsmDataLayer then projected coordinates will not get updated. Maybe Node.getEastNorth should recalculate coordinates every time if it has no Dataset assigned.

Dataset without OsmDataLayer - only way I can think of is having Dataset directly registered as ProjectionChangedListener (via SoftReference to prevent memory leaks).

by anonymous, 14 years ago

Updated patch (forgot to remove one premature optimization in NodeData)

comment:4 by bastiK, 14 years ago

Only a small fraction of users will switch projections regularly, so errors might creep in and stay undetected. But I guess it's worth it. Some minor comments:

in reply to:  3 comment:5 by anonymous, 14 years ago

Replying to jttt:

I think it's a bit error-prone. If Node is not part of the Dataset and Dataset part of OsmDataLayer then projected coordinates will not get updated. Maybe Node.getEastNorth should recalculate coordinates every time if it has no Dataset assigned.

Dataset without OsmDataLayer - only way I can think of is having Dataset directly registered as ProjectionChangedListener (via SoftReference to prevent memory leaks).

Thanks, jttt. See last three commits in https://github.com/Gubaer/josm/commits/cached-lat-lon

in reply to:  4 ; comment:6 by anonymous, 14 years ago

  • Why is CachedLatLon "uncached"? Isn't it enough to deprecate the class?

Yes.

  • The projected coordinates could be calculated "on demand". (Just a matter of taste, imagine JOSM would run in headless mode and could be used as a tool like osmosis. Then the projecting would be unnecessary.)

JOSM in headless mode? Hmm, personally I rather doubt about it. But calculating coordinates on demand? Yes, why not.

Yes. Later I'm going to supply a new version of the patch, including the latest modifications and including ProjectionChangeListener

in reply to:  6 ; comment:7 by bastiK, 14 years ago

Replying to anonymous:

  • The projected coordinates could be calculated "on demand". (Just a matter of taste, imagine JOSM would run in headless mode and could be used as a tool like osmosis. Then the projecting would be unnecessary.)

JOSM in headless mode? Hmm, personally I rather doubt about it. But calculating coordinates on demand? Yes, why not.

Off topic: There could be command line rendering like that: java -jar josm-tested.jar --render --input city.osm --style test.mapcss --scale 20000 --bounds ... --output city.png. This still projects all the Nodes, but it would be a start for headless mode.

in reply to:  7 ; comment:8 by anonymous, 14 years ago

Replying to bastiK:

Replying to anonymous:

  • The projected coordinates could be calculated "on demand". (Just a matter of taste, imagine JOSM would run in headless mode and could be used as a tool like osmosis. Then the projecting would be unnecessary.)

JOSM in headless mode? Hmm, personally I rather doubt about it. But calculating coordinates on demand? Yes, why not.

Off topic: There could be command line rendering like that: java -jar josm-tested.jar --render --input city.osm --style test.mapcss --scale 20000 --bounds ... --output city.png. This still projects all the Nodes, but it would be a start for headless mode.

I onced tried to do offline rendering in order to performance test MapCSS rendering, see https://github.com/Gubaer/josm/blob/mirror/test/functional/mapcss/performance/PerformanceTest.groovy

I was able to render into an image by supplying a custom Grapics2D context, but I nevertheless neded a MapView because it is currently tightly coupled with map rendering. That's why, I doubt, that JOSM is currently ready for headless rendering. But I have to admit that I didn't spend a lot of time with this, I can easily have overlooked something.

comment:9 by stoecker, 14 years ago

The CachedLatLon was introduced by me a long time ago, as there were performance problems with permanent coordinate calculations. Since then a lot in the infrastructure has changed, so we should really test if "on demand" is possible now again. If would certainly make the whole stuff a lot easier (I never liked CachedLatLon at all).

But drawing must not get slower.

But this only applies to the data we actually draw. Probably we can calculate these values on demand for everything which does not match the "in an osm data layer" assumption. This may help to get complexity in balance with execution speed.

in reply to:  9 ; comment:10 by bastiK, 14 years ago

Replying to stoecker:

The CachedLatLon was introduced by me a long time ago, as there were performance problems with permanent coordinate calculations. Since then a lot in the infrastructure has changed, so we should really test if "on demand" is possible now again. If would certainly make the whole stuff a lot easier (I never liked CachedLatLon at all).

What I mean by "on demand", is to initialize the cache with NaN and keep it this way until EastNorth is requested for the first time. For subsequent calls, the cached value is returned. (Lazy evaluation)


But drawing must not get slower.
But this only applies to the data we actually draw. Probably we can calculate these values on demand for everything which does not match the "in an osm data layer" assumption. This may help to get complexity in balance with execution speed.

Agreed.

in reply to:  10 comment:11 by anonymous, 14 years ago

What I mean by "on demand", is to initialize the cache with NaN and keep it this way until EastNorth is requested for the first time. For subsequent calls, the cached value is returned. (Lazy evaluation)

Me too, see https://github.com/Gubaer/josm/commits/cached-lat-lon

comment:12 by stoecker, 14 years ago

In last change: I would drop the "if (Main.getProjection() == null) return; // sanity check" in the invalidate function.

Last edited 14 years ago by stoecker (previous) (diff)

comment:13 by stoecker, 14 years ago

@bastik: Do we want to make a release first or delay it and apply this now (we had a lot of API changes already, so I doubt the plugins are all up-to-date anyway)?

in reply to:  13 comment:14 by bastiK, 14 years ago

Replying to stoecker:

@bastik: Do we want to make a release first or delay it and apply this now (we had a lot of API changes already, so I doubt the plugins are all up-to-date anyway)?

Doesn't matter to me, both is possible. In case of delayed release, we could include the parallel way feature, as well.

in reply to:  8 comment:15 by bastiK, 14 years ago

Replying to anonymous:

Replying to bastiK:

Replying to anonymous:

  • The projected coordinates could be calculated "on demand". (Just a matter of taste, imagine JOSM would run in headless mode and could be used as a tool like osmosis. Then the projecting would be unnecessary.)

JOSM in headless mode? Hmm, personally I rather doubt about it. But calculating coordinates on demand? Yes, why not.

Off topic: There could be command line rendering like that: java -jar josm-tested.jar --render --input city.osm --style test.mapcss --scale 20000 --bounds ... --output city.png. This still projects all the Nodes, but it would be a start for headless mode.

I onced tried to do offline rendering in order to performance test MapCSS rendering, see https://github.com/Gubaer/josm/blob/mirror/test/functional/mapcss/performance/PerformanceTest.groovy

I was able to render into an image by supplying a custom Grapics2D context, but I nevertheless neded a MapView because it is currently tightly coupled with map rendering. That's why, I doubt, that JOSM is currently ready for headless rendering. But I have to admit that I didn't spend a lot of time with this, I can easily have overlooked something.

I think you are right, but that doesn't mean it can't be fixed.

by anonymous, 14 years ago

Updated patch against JOSM 4115, includes suggestions from this ticket

comment:16 by stoecker, 14 years ago

1) Please remove CachedLatLon totally:

  • it is only used by editgpx plugin
  • it would be dropped from released .jar anyway, as it is no longer used in core

2) Setting a SubPrefs projection fails:

  • If I try UTM zone 33 in prefs, I get UTM zone 30 as result in the mapview.

3) A minor issue: GpxLayer misses a return at file end.

comment:17 by anonymous, 14 years ago

I won't supply another patch. 1) and 3) can be fixed by anybody in less than five minutes. Don't try to keep me busy.

Ad 2): Try to replace this with

if (p instanceof ProjectionSubPrefs) {
   ((ProjectionSubPrefs) p).setPreferences(coll);
}

comment:18 by stoecker, 14 years ago

Sure 1 and 3 are trivial and I already did these. 2 was the reason why I did not apply the patch yet.

But your answer again gives me doubt whether to apply it at all. This was the problem with your changes in the past and it seems it still is - you make great adaptions, but are not willing to fix all the little quirks related to these. I don't have enough time to do this myself so I must rely on the original patch authors.

comment:19 by anonymous, 14 years ago

Resolution: invalid
Status: newclosed

Closing. Not worth the trouble. Please don't apply the patch.

comment:20 by anonymous, 14 years ago

In [4126] integrated by bastik. Thanks.

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.