Optimizing this method (HashSet.RemoveWhere performance issue) I have the following method:

public static HashSet&lt;PathDetails&gt; GetDeletedPaths(HashSet&lt;PathDetails&gt; old, HashSet&lt;PathDetails&gt; current)
{
    var deleted = new HashSet&lt;PathDetails&gt;(old);
    deleted.RemoveWhere(x =&gt; current.Any(y =&gt; y.Path == x.Path));
    return deleted;
}


PathDetails is a struct that, among other things, contains Path of type String. This method takes the longest in my application and I was wondering if there were any good ways of improving its performance. These hash sets are used elsewhere in a more hashset-friendly way, so the method must take in two sets and return a set.
Instead of using the RemoveWhere() method together with the Any() method you should consider to just use ExceptWith() method.   

public static HashSet&lt;PathDetails&gt; GetDeletedPaths(HashSet&lt;PathDetails&gt; old, HashSet&lt;PathDetails&gt; current)
{
    var deleted = new HashSet&lt;PathDetails&gt;(old);
    deleted.ExceptWith(current);
    return deleted;
}


Your approach calls for each item in deleted the Any() of current whereas ExceptWith() just calls for each item in current the Remove() method of deleted.