Moved instance loop into C to avoid setup/teardown overhead.