Opened 13 years ago

Last modified 13 years ago

#8643 closed defect

[patch] Very slow Purge command - O(N^2) — at Initial Version

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

Description

There is bad algorithm used in Purge command, with complexity O(N2), causing purge with about 176000 ways to take over 15 minutes.

Problem is in toposort, where the algorithm restart iteration over the hashset after every deleted way, but in Javaadoc for HashMap it says:

Iteration over collection views requires time proportional to the "capacity" of the HashMap instance (the number of buckets) plus its size (the number of key-value mappings).

As the capacity still remains the same as the collection becomes more and more empty, this effectively is O(N2) algorithm, as it takes longer and longer time to iterate to first way (not mentioning skipping all the nodes again and again before encountering a corresponding way).

The patch fixes the topopSort and reduces the time it needs to process the data

For purging collection of about 176000 ways and 800000 nodes the time for toposort is reduced from about 17 minutes to 500 milliseconds.

Change History (1)

by bilbo, 13 years ago

Attachment: purgemod2.diff added

Much faster Purge command

Note: See TracTickets for help on using tickets.