View Issue Details

IDProjectCategoryView StatusLast Update
0003179.NET APIPerformance Problempublic2015-09-30 11:23
ReporterAntti Pirilä Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
Status newResolutionopen 
PlatformPCOSWindowsOS Version8.1
Summary0003179: Bad performance of RemoveItems
Description

The performance of RemoveItems method was bad due to O(n^2) algorith used. The RemoveItems looped the subscribed items once for each removed item. I have subscribed something like 10 000 items and removing them required several seconds of CPU time.

Here is a new fixed method:
/// <summary>
/// Removes items from a subsription.
/// </summary>
public virtual IdentifiedResult[] RemoveItems(ItemIdentifier[] items)
{
if (items == null) throw new ArgumentNullException("items");

        // check if there is nothing to do.
        if (items.Length == 0)
        {
            return new IdentifiedResult[0];
        }

        // remove items from server.
        IdentifiedResult[] results = m_subscription.RemoveItems(items);

        if (results == null || results.Length == 0) 
        {
            throw new InvalidResponseException();
        }

        // Fix starts
        var removedHandles = new HashSet&lt;object>();
        foreach (var result in results)
        {
            if (result.ResultID.Succeeded())
            {
                removedHandles.Add(result.ServerHandle);
            }
        }
        // Fix ends

        // remove items from local list if successful.
        ArrayList itemList = new ArrayList();

        foreach (Item item in m_items)
        {
            // Fix starts
            if (!removedHandles.Contains(item.ServerHandle))
            {
                itemList.Add(item);
            }
            // Fix ends
        }

        // update local list.
        m_items = (Item[])itemList.ToArray(typeof(Item));

        // update the local state.
        GetState();

        // return results.
        return results;
    }
Steps To Reproduce

Subscribe 10 000 items and remove all of them.

TagsNo tags attached.

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2015-09-30 11:23 Antti Pirilä New Issue