Cache and reuse groups during model instancing.

For #2024.