optimization for IOmemory's len function

no need to iterate over the set anymore.