Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: cmd/go: make build cache trimming cutoff configurable #69879

Open
matthalp opened this issue Oct 14, 2024 · 7 comments
Open

proposal: cmd/go: make build cache trimming cutoff configurable #69879

matthalp opened this issue Oct 14, 2024 · 7 comments
Labels
Milestone

Comments

@matthalp
Copy link

Proposal Details

The current policy assumes that caching is being used by a single developer. However, there are scenarios where the cache is shared across multiple developers and the cache size accumulation can have meaningful impact.

For example, CI where there can be many developers contributing code in a single day and leveraging a shared cache (e.g. GitHub Actions Cache where there is a cache size limit and also time spent loading and saving the cache). In these cases, 5 days of cache accumulation can have meaningful impacts.

Thank you for your consideration!

@gopherbot gopherbot added this to the Proposal milestone Oct 14, 2024
@matthalp
Copy link
Author

Another option that just came to mind is to expose cache trimming on the tool chain to be able to explicitly call it with various some configurability as well.

@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Oct 14, 2024
@seankhliao seankhliao changed the title proposal: cmd/go: make cache trimming cutoff configurable proposal: cmd/go: make build cache trimming cutoff configurable Oct 14, 2024
@seankhliao
Copy link
Member

@gabyhelp
Copy link

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@matthalp
Copy link
Author

@ianlancetaylor @matloob I wanted to put this on your radar. I like the GODEBUG variable idea mentioned in #69565 (comment)

P.S. @ianlancetaylor you were my go code readability reviewer in another life 👋

@matloob
Copy link
Contributor

matloob commented Nov 12, 2024

@matthalp Have you looked at GOCACHEPROG (it is currently not enabled by default but there's an accepted proposal to do so in 1.24)? You could use it to implement a cache with a custom policy.

@matthalp
Copy link
Author

Thank you @matloob! I had not seen that before.

I can look into a custom cache implementation, but I feel like my use case -- as well as the one in #69565 -- would be enabled by making variables configurable in some way. Is that something you would be open to?

From https://cs.opensource.google/go/go/+/refs/tags/go1.23.3:src/cmd/go/internal/cache/cache.go;l=334-335

//
// We set the mtime on a cache file on each use, but at most one per mtimeInterval (1 hour),
// to avoid causing many unnecessary inode updates. The mtimes therefore
// roughly reflect "time of last use" but may in fact be older by at most an hour.
//
// We scan the cache for entries to delete at most once per trimInterval (1 day).
//
// When we do scan the cache, we delete entries that have not been used for
// at least trimLimit (5 days). Statistics gathered from a month of usage by
// Go developers found that essentially all reuse of cached entries happened
// within 5 days of the previous reuse. See golang.org/issue/22990.
const (
	mtimeInterval = 1 * time.Hour
	trimInterval  = 24 * time.Hour
	trimLimit     = 5 * 24 * time.Hour
)

@matloob
Copy link
Contributor

matloob commented Dec 9, 2024

@matthalp I don't think that's something we'd want to do unless we had a strong reason for it. Each additional bit of configuration adds complexity to the command and we'd need to have a strong reason to add it to balance out the complexity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

5 participants