Modify

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#5552 closed enhancement (fixed)

[PATCH] Delete performance improvement

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

Description

Improved delete selected objects performance.

Attachments (2)

deleteSpeed.diff (1.8 KB ) - added by extropy 14 years ago.
deleteSpeed-2.diff (1.9 KB ) - added by extropy 14 years ago.
Fixed nodes counter

Download all attachments as: .zip

Change History (14)

by extropy, 14 years ago

Attachment: deleteSpeed.diff added

comment:1 by bastiK, 14 years ago

Summary: Delete performance improvement[PATCH] Delete performance improvement

Your patch looks a little strange.

                List<Node> copy = new ArrayList<Node>(this.getNodesCount() - nodesToRemove); 

Isn't nodesToRemove the same as getNodesCount(), so you get 0?

in reply to:  1 comment:2 by extropy, 14 years ago

Replying to bastiK:

Your patch looks a little strange.

                List<Node> copy = new ArrayList<Node>(this.getNodesCount() - nodesToRemove); 

Isn't nodesToRemove the same as getNodesCount(), so you get 0?

This method is called from DeleteCommand.

No, nodesToRemove is a list of nodes to delete - possibly a list of selected nodes that is only a part of all ways nodes.

comment:3 by bastiK, 14 years ago

isn't it and integer rather than a list?

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

Replying to bastiK:

isn't it and integer rather than a list?

It certainly is. The idea is to initialize the list to the needed size. The default size is 10. This avoids reallocation if there are more than 10 items and saves memory as the array is precisely as long as needed.

See http://download.oracle.com/javase/1.4.2/docs/api/java/util/ArrayList.html#ArrayList%28int%29

comment:5 by bastiK, 14 years ago

You can replace

        302	            int nodesToRemove = 0; 
 	303	            for (Node n: nodes) { 
 	304	                nodesToRemove ++; 
 	305	            } 

by

        	            int nodesToRemove = nodes.size(); 

so why is this needed?

by extropy, 14 years ago

Attachment: deleteSpeed-2.diff added

Fixed nodes counter

comment:6 by extropy, 14 years ago

That is a bug :(.

Uploaded fixed version.

comment:7 by bastiK, 14 years ago

Are you sure, counting nodesToRemove in advance is a performance gain? Calling contains() can be expensive (compared to the other stuff)...

comment:8 by extropy, 14 years ago

The initial counting may indeed be removed, it just optimizes memory consumption.

About performance: let's do a full analysis.
Let A = number of nodes in way, B = number of objects in selection

Old code:

  • For each node in selection, call removeNode.
  • RemoveNode works O(A)
  • Total complexity is O(A*B)

New code:

  • For each node in way test if it is not in selection and if so add to the new nodes list.
  • selection.contains() on a Set should be O(1). In reality it is a hash set and it actually is O(1).
  • Total complexity is O(A)

Now let's assume we want to delete Y ways, containing X nodes.

  • Old code would work in O(X*X).
  • New code would work in O(X).

Hope this helps.

comment:9 by bastiK, 14 years ago

Resolution: fixed
Status: newclosed

In [3630/josm]:

applied #5552 (patch by extropy) - Delete performance improvement

comment:10 by bastiK, 14 years ago

Ok, I removed initial counting - but not because it has a great impact on performance, but simply to keep the code slim. Every line of code that is not needed can contain bugs. See above for an example. ;)

comment:11 by extropy, 14 years ago

Fine.

I'm just generally concerned about memory consumption. Ways are basic primitives and usually there are tens of thousands of them in a dataset, so every byte counts.

comment:12 by bastiK, 14 years ago

Long term memory consumption is not an issue, because setNodes() takes care of the correct Array size. Otherwise you are right, of course.

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.