### 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
self.pending_redirect = None
        self.plugin_resolved_name = resolved_name
        self.plugin_resolved_path = resolved_path
        self.plugin_resolved_collection = resolved_collection
        self.exit_reason = exit_reason
        self.resolved = True
        self.action_plugin = action_plugin
        return self
    def redirect(self, redirect_name):
        self.pending_redirect = redirect_name
        self.exit_reason = 'pending redirect resolution from {0} to {1}'.format(self.original_name, redirect_name)
        self.resolved = False
        return self
    def nope(self, exit_reason):
        self.pending_redirect = None
        self.exit_reason = exit_reason
        self.resolved = False
        return self
class PluginLoader:
    '''
    PluginLoader loads plugins from the configured plugin directories.
    It searches for plugins by iterating through the combined list of play basedirs, configured
    paths, and the python path.  The first match is used.
    '''
    def __init__(self, class_name, package, config, subdir, aliases=None, required_base_class=None):