@Override
    public boolean retainAll(final Collection<?> arg) {
        boolean changed = false;
        for (int i = 0; i < size; ++i) {
            final Object entry = entries[i];
            if ( !arg.contains(entry)) {
                entries[i] = null;
                changed = true;
            }
        }
        if (changed) {
            clean();
        }
        return changed;
    }
This is an extremely expensive implementation of
{@link Set#retainAll(Collection)}. It is implemented as O(n**2).
vespajlib/src/main/java/com/yahoo/collections/ArraySet.java