SERVER-31428 moved the generation of the CollectionMetadata chunksMap into the MODE_X collection lock section, as a way of serialising concurrent metadata refreshes, and thereby avoiding the redundant computation performance penalty from all metadata refreshing threads generating the map at the same time. However, all that is actually required is to ensure that this map is generated only once, by one thread, ie. it isn't necessary to hold the MODE_X collection lock to create this data structure. Therefore it would be better if this map was created outside the collection lock (by just one thread), to reduce the time that it's held.
Most likely this will involve a variant of CatalogCache::getCollectionRoutingInfo, which accepts a lambda to be called-back (guaranteed by a single thread) and this lambda is what updates the metadata on the CollectionShardingState.