Implementors of memoryCost() need to be thread-safe.