Skip to content

providercache: hash cached provider packages only once - #39253

Open
Dutchy- wants to merge 3 commits into
hashicorp:mainfrom
Dutchy-:init-hash-cached-provider-once
Open

Dutchy- wants to merge 3 commits into
hashicorp:mainfrom
Dutchy-:init-hash-cached-provider-once

Conversation

@Dutchy-

@Dutchy- Dutchy- commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

When terraform init links a provider from the global plugin cache and the dependency lock file already has checksums for it, the installer read and hashed the entire cached package three times. It now hashes it once and reuses the result. The lock file checks themselves are unchanged.

For a configuration that only requires hashicorp/aws 6.44.0 (770MB unpacked), with a lock file and a warm plugin cache, terraform init on an Apple silicon Mac went from 1.28s to 0.50s wall time and from 0.99s to 0.35s CPU time (median of 8 runs).

The existing TestEnsureProviderVersions cases cover each branch of this path: no lock entry, matching and mismatching checksums, and plugin_cache_may_break_dependency_lock_file. The second commit adds a test that counts how often the cached package is hashed. It fails on main (3 reads instead of 1). It relies on a test hook in cached_provider.go, and I'm unsure whether that's acceptable here, even with precedent such as testChecksumHook in the s3 and oss backends. I'm happy to drop that commit if you'd rather not have it.

Fixes #39252

AI disclosure

I used Claude Code (Claude Opus 5) for this PR. It found the problem while profiling terraform init, wrote the change and the test, ran the benchmarks, and drafted the commit messages and this description. I reviewed the change and the test and can explain both.

Target Release

1.18.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

None. Cache entries are still verified against the lock file before use. The second check before linking is skipped only after the first one has passed on the same cache entry.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@Dutchy-
Dutchy- requested a review from a team as a code owner September 21, 2026 09:35
@hashicorp-cla-app

hashicorp-cla-app Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

When init links a provider from the global plugin cache and the dependency
lock file already has checksums for it, the installer computed the same h1
hash of the cached package three times: to decide whether the cache entry
matches the lock file, again inside LinkFromOtherCache, and once more for the
lock file update. Each hash reads the whole package, which for large
providers such as hashicorp/aws (around 770MB unpacked) takes most of a
second. The hash is now computed at most once per cache entry and reused, and
still only when something needs it. The lock file checks are unchanged.
Adds a test hook to the CachedProvider hashing methods and a test that
counts how often EnsureProviderVersions reads a package from the global
plugin cache: once when the lock file has checksums for it or the cache may
break the lock file, and not at all when the entry isn't eligible.
@Dutchy-
Dutchy- force-pushed the init-hash-cached-provider-once branch from c364d42 to 83fd380 Compare September 21, 2026 17:56

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

terraform init hashes a cached provider package three times when linking it from the plugin cache

2 participants