Is it possible to specify a task as cacheable loca...
# caching
c
Is it possible to specify a task as cacheable locally only? I’ve noticed that tasks with very small outputs (and generally fast execution) don’t benefit much from cacheing and the RTT to remote is typically negative.
👀 1
e
not as far as I know, but perhaps you could disable caching for those tasks in particular? even without cache, you should still have up-to-date checks that allow them to be skipped locally if the inputs/outputs haven't changed
c
Yeah was considering that too. It’s sort of hard for me to grok which tasks have a net benefit vs. net negative. I wish I could show avoidance savings as a column in the scan timeline (and wish i could order by savings)
e
https://docs.gradle.org/current/javadoc/org/gradle/work/DisableCachingByDefault.html
Not all work benefits from caching: for example tasks that only copy content around on disk rarely do.
gives a little guidance
c
Yeah I know this is expected behavior, it still doesn’t make it super straight forward to solve 🤷
TBH my hypothetical ideal is some sort of smart caching on gradle/develocity side where if fetching from cache has been a net negative for a specific host previously it doesn’t try again for some time period (or performs an async check to see if it’s still slower from cache)
In general our CI caching is always positive since the host and cache are basically next to eachother. For local devs we see a lot more negative caching
v
The remembering would not make much sense. When you get an entry from remote cache it is also put to local cache afair, so the next cache use would be from local directly.
c
Not exactly sure? It would just mean we run the task to populate our local cache instead right? isn’t the net results still faster?
v
I don't get what you mean. If I got you right you suggested that Gradle automatically determines when a remote cache hit was a net negative and does not ask the remote cache again. I said this does not make sense as after the first remote cache hit you anyway get local cache hits
c
I don’t mean for the full cache key, but at the task level
so if some
packageResource
task ends up as a net-negative on the remote cache, the next time the inputs change for that task, it doesn’t ask the remote and instead runs the tasks
e
how does it know if it ends up net-negative or not? just run every task and compare how long it takes?
c
i donno, probably do it on the cache server side 🤷
dont make the determination locally
e
the cache server has no idea what any of the cache entries mean so that's even less possible 🤷
c
haha okay then yeah
but you crushing my dreams! 😆
v
The cache server is only a dumb file store. But the creator of a cache entry could surely add to the metadata what you can save. Actually, I think it already saves that, so that in a build scan you can already display the savings which also sometimes happen to be negative: https://scans.gradle.com/s/qf4quvqgyasda/timeline?details=5hmtaw3jwchdw&expanded=WyIxIl0&hide-timeline&kind=task&outcome=from-cache&sort=longest So such a feature might indeed be possible with not too much effort. Whether the Gradle folks deem it worth, you have to find out with opening a feature request. :-)
t
The savings here appear to be what you would save with task avoidance: here the task took 0.137s, with 0.130s attributed to the build cache. Had the task been UP-TO-DATE, this would have saved 0.130s. It doesn't say what build cache saved versus actually running the task though.
v
Are you sure?
https://gradle.com/develocity/product/performance-insights/
Avoidance savings
Understand where you're saving the most time—for example, thanks to the remote cache or up-to-date Gradle builds.
t
Are you sure?
Not at all 🤣 That's just how I interpret what I'm seeing in the scan
v
https://gradle.com/develocity/legacy-releases/2019.4#inspect-avoidance-savings-for-individual-builds
An “avoidance saving” is an estimate of the amount of time saved when execution of a Gradle task or Maven goal was avoided due to reuse of existing outputs. It is measured as the difference between the time taken to originally do the work, and the time taken to reuse it (e.g. download from remote build cache). For Gradle builds, outputs can be reused via incremental building and build caching, while for Maven builds build caching is the only avoidance mechanism.
Of course this is always just an estimate, because for example the build agent can be 3 times as powerful as your local machine, so it could think you only saved 1 minute when you actually saved 3 minutes. So the suggested feature might indeed be more difficult to get done right, if that should also be attribute for.
Additionally, the build cache can also contain results from differently performing agents.
That in the linked example both numbers are 0.130s is just a coincidence. It means that it was expensive to reuse the cache as you have a negative savings.
👍 1