### Summary

Dynamic inventories have grown particularly slow when they load up a large number of machines. Our inventory of 10k+ nodes is taking a little over 60 seconds from command start to the first ansible task running - assuming a fully cached local inventory which skips the fetch calls.

The issue appears to have started somewhere around Ansible 4.
Edit: Updated to highlight the core 2.11.11 -> 2.11.12 2x speed increase. I'm still searching for a way to find where the 3.4 -> 4.0 one may be.
```
ansible              3.4.0
ansible-base         2.10.17
7 seconds

ansible              4.0.0
ansible-core         2.11.11
19 seconds

ansible              4.0.0
ansible-core         2.11.12
46 seconds

ansible              4.10.0
ansible-core         2.11.12
41 seconds

ansible              6.4.0
ansible-core         2.13.4
73 seconds - Note: this is longer as caching is not working due to a separate issue
47 seconds (with the fetch step excluded)
```

The V4 -> V6 increase is likely #78767 but this wouldn't explain the 4x jump from V3 -> V4.


### Issue Type

Bug Report

### Component Name

inventory

### Ansible Version

```console
$ ansible --version
ansible [core 2.13.4]
  config file = /usr/share/ansible/ansible.cfg
  configured module search path = ['/usr/share/ansible/library']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /usr/lib/python3.8/site-packages/ansible_collections
  executable location = /usr/bin/ansible
  python version = 3.8.13 (default, Apr 28 2022, 12:34:52) [GCC 8.3.1 20190311 (Red Hat 8.3.1-3)]
  jinja version = 3.1.2
  libyaml = True
```


### Configuration

```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CALLBACKS_ENABLED(/usr/share/ansible/ansible.cfg) = ['syslog', 'timer', 'yaml']
COLLECTIONS_PATHS(/usr/share/ansible/ansible.cfg) = ['/usr/lib/python3.8/site-packages/ansible_collections']
COLOR_VERBOSE(/usr/share/ansible/ansible.cfg) = bright blue
DEFAULT_ACTION_PLUGIN_PATH(/usr/share/ansible/ansible.cfg) = ['/usr/share/ansible/plugins/action']
DEFAULT_CALLBACK_PLUGIN_PATH(/usr/share/ansible/ansible.cfg) = ['/usr/share/ansible/plugins/callback']
DEFAULT_FILTER_PLUGIN_PATH(/usr/share/ansible/ansible.cfg) = ['/usr/share/ansible/plugins/filter']
DEFAULT_GATHERING(/usr/share/ansible/ansible.cfg) = smart
DEFAULT_HOST_LIST(/usr/share/ansible/ansible.cfg) = ['/usr/share/ansible/inventory/consort.yml']
DEFAULT_INVENTORY_PLUGIN_PATH(/usr/share/ansible/ansible.cfg) = ['/usr/share/ansible/plugins/inventory']
DEFAULT_LOAD_CALLBACK_PLUGINS(/usr/share/ansible/ansible.cfg) = True
DEFAULT_LOG_PATH(/usr/share/ansible/ansible.cfg) = /root/.ansible/logs/ansible.log
DEFAULT_LOOKUP_PLUGIN_PATH(/usr/share/ansible/ansible.cfg) = ['/usr/share/ansible/plugins/lookup']
DEFAULT_MODULE_PATH(/usr/share/ansible/ansible.cfg) = ['/usr/share/ansible/library']
DEFAULT_MODULE_UTILS_PATH(/usr/share/ansible/ansible.cfg) = ['/usr/share/ansible/module_utils']
DEFAULT_ROLES_PATH(/usr/share/ansible/ansible.cfg) = ['/usr/share/ansible/roles']
DEFAULT_STDOUT_CALLBACK(/usr/share/ansible/ansible.cfg) = yaml
DEFAULT_TIMEOUT(/usr/share/ansible/ansible.cfg) = 15
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /root/.ansible/.vault_pass.key
INVENTORY_CACHE_PLUGIN(/usr/share/ansible/ansible.cfg) = jsonfile
INVENTORY_CACHE_PLUGIN_CONNECTION(/usr/share/ansible/ansible.cfg) = /root/.ansible/cache
RETRY_FILES_ENABLED(/usr/share/ansible/ansible.cfg) = False
TRANSFORM_INVALID_GROUP_CHARS(/usr/share/ansible/ansible.cfg) = ignore

CONNECTION:
==========

ssh:
___
pipelining(/usr/share/ansible/ansible.cfg) = True
ssh_args(/usr/share/ansible/ansible.cfg) = -C -o ServerAliveInterval=5 -o ServerAliveCountMax=2 -o ControlMaster=auto -o ControlPersist=120s -o PreferredAuthentications=publickey,password -o UserKnownHostsFile=/dev/null -o StrictHostKe
timeout(/usr/share/ansible/ansible.cfg) = 15

INVENTORY:
=========

consort:
_______
cache_connection(/usr/share/ansible/ansible.cfg) = /root/.ansible/cache
cache_plugin(/usr/share/ansible/ansible.cfg) = jsonfile
```


### OS / Environment

Centos 7 Docker container

### Steps to Reproduce

Example timings from the hosts
```
ansible              3.4.0
ansible-base         2.10.17

Averages around 7 seconds to process the inventory and start tasks

# time ansible localhost -vvvv --list-hosts
ansible 2.10.17
  config file = /usr/share/ansible/ansible.cfg
  configured module search path = ['/usr/share/ansible/library']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.13 (default, Apr 28 2022, 12:34:52) [GCC 8.3.1 20190311 (Red Hat 8.3.1-3)]
Using /usr/share/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /usr/share/ansible/inventory/consort.yml as it did not pass its verify_file() method
script declined parsing /usr/share/ansible/inventory/consort.yml as it did not pass its verify_file() method
inventory/consort _populate took 3337ms
inventory/consort parse took 4046ms
Parsed /usr/share/ansible/inventory/consort.yml inventory source with auto plugin
  hosts (1):
    localhost

real    0m12.943s
user    0m10.350s
sys     0m1.612s

#######

ansible              4.10.0
ansible-core         2.11.12

# time ansible localhost -vvvv --list-hosts
ansible [core 2.11.12]
  config file = /usr/share/ansible/ansible.cfg
  configured module search path = ['/usr/share/ansible/library']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /usr/lib/python3.8/site-packages/ansible_collections
  executable location = /usr/bin/ansible
  python version = 3.8.13 (default, Apr 28 2022, 12:34:52) [GCC 8.3.1 20190311 (Red Hat 8.3.1-3)]
  jinja version = 3.1.2
  libyaml = True
Using /usr/share/ansible/ansible.cfg as config file
[DEPRECATION WARNING]: [defaults]callback_whitelist option, normalizing names to new standard, use callbacks_enabled instead. This feature will be removed from ansible-core in version 2.15. Deprecation warnings can be disabled by
setting deprecation_warnings=False in ansible.cfg.
setting up inventory plugins
host_list declined parsing /usr/share/ansible/inventory/consort.yml as it did not pass its verify_file() method
script declined parsing /usr/share/ansible/inventory/consort.yml as it did not pass its verify_file() method
inventory/consort _populate took 3284ms
inventory/consort parse took 3972ms
Parsed /usr/share/ansible/inventory/consort.yml inventory source with auto plugin
  hosts (1):
    localhost

real    0m36.764s
user    0m34.052s
sys     0m1.802s


########

ansible              6.4.0
ansible-core         2.13.4

# time ansible localhost -vvvv --list-hosts
ansible [core 2.13.4]
  config file = /usr/share/ansible/ansible.cfg
  configured module search path = ['/usr/share/ansible/library']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /usr/lib/python3.8/site-packages/ansible_collections
  executable location = /usr/bin/ansible
  python version = 3.8.13 (default, Apr 28 2022, 12:34:52) [GCC 8.3.1 20190311 (Red Hat 8.3.1-3)]
  jinja version = 3.1.2
  libyaml = True
Using /usr/share/ansible/ansible.cfg as config file
[DEPRECATION WARNING]: [defaults]callback_whitelist option, normalizing names to new standard, use callbacks_enabled instead. This feature will be removed from ansible-core in version 2.15. Deprecation warnings can be disabled by
setting deprecation_warnings=False in ansible.cfg.
setting up inventory plugins
host_list declined parsing /usr/share/ansible/inventory/consort.yml as it did not pass its verify_file() method
script declined parsing /usr/share/ansible/inventory/consort.yml as it did not pass its verify_file() method
Using inventory plugin 'consort' to process inventory source '/usr/share/ansible/inventory/consort.yml'
inventory/consort _populate took 3272ms
inventory/consort parse took 3902ms
Parsed /usr/share/ansible/inventory/consort.yml inventory source with auto plugin
  hosts (1):
    localhost

real    0m39.021s
user    0m35.999s
sys     0m1.989s
```


### Expected Results

Less of an increase in the inventory parsing between the versions.

### Actual Results

```console
Long startup times processing the inventory data on every command.

Possibly not related but we did see a behaviour changing during the post populate stage where ansible was doing a lot of calls to `host_group_vars`

  2026 1662134089.85213: Loading VarsModule 'host_group_vars' from /usr/lib/python3.8/site-packages/ansible/plugins/vars/host_group_vars.py (found_in_cache=True, class_only=False)
  2026 1662134089.86151: Loading ModuleDocFragment 'vars_plugin_staging' from /usr/lib/python3.8/site-packages/ansible/plugins/doc_fragments/vars_plugin_staging.py (found_in_cache=True, class_only=False)
  2026 1662134089.86523: Loaded config def from plugin (vars/host_group_vars)
```
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct
if not requirement_string:
        return True
    if not SpecifierSet:
        display.warning('packaging Python module unavailable; unable to validate collection Ansible version requirements')
        return True
    ss = SpecifierSet(requirement_string)
    
    base_ansible_version = Version(ansible_version).base_version
    return ss.contains(base_ansible_version)
def _configure_collection_loader():
    if AnsibleCollectionConfig.collection_finder:
        
        warnings.warn('AnsibleCollectionFinder has already been configured')
        return
    finder = _AnsibleCollectionFinder(C.COLLECTIONS_PATHS, C.COLLECTIONS_SCAN_SYS_PATH)
    finder._install()
    
    AnsibleCollectionConfig.on_collection_load += _on_collection_load_handler
_PLUGIN_FILTERS = _load_plugin_filter()
_configure_collection_loader()
fragment_loader = PluginLoader(
    'ModuleDocFragment',
    'ansible.plugins.doc_fragments',
    C.DOC_FRAGMENT_PLUGIN_PATH,
    'doc_fragments',
)
action_loader = PluginLoader(
    'ActionModule',
    'ansible.plugins.action',
    C.DEFAULT_ACTION_PLUGIN_PATH,