saltstack / saltstack/salt

[BUG] state.apply is very slow when filesever has many (10,000+) files

Open
#65,348 1 comment 1 reaction 1 assignee View on GitHub

@charzl is already working on this.

Since Jul 13, 2026.

bug needs-triage Performance State-Compiler
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
One of the first steps of compiling a state is to build a list of all available states, either immediately, or when first accessed for a particular saltenv: https://github.com/saltstack/salt/blob/v3006.3/salt/state.py#L3705

This involves scanning the entire fileserver. If it contains a lot of files, then this can take significant time.

This appears to be done so that fnmatch.filter can be run across the resulting list when processing sls to include, but I wasn't aware that patterns were supported. Certainly neither the top.sls documentation nor the include documentation mentions it.

If that feature is indeed not supported, it could instead directly query for the candidate file (caching it in the process if not already) from the fileserver, removing the need for this list in the first place.

Setup
This is an easy way to do it, or generate a dummy tree if you prefer:

file_roots:
  base:
    - /srv/salt
    - /

Steps to Reproduce the behavior
salt-call state.apply

Expected behavior
Time spent building a state should scale with the complexity of the state, and remain constant w.r.t. the size of the fileserver.

Versions Report
Any version, but confirmed with 3006.3.

Additional context
Some discussion: https://saltstackcommunity.slack.com/archives/C8832QN4U/p1696507451742969?thread_ts=1696506150.079679&cid=C8832QN4U

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.