Is it possible to avoid ValueSource.obtain being called?

ConfigurationCacheFingerprintChecker.checkFingerprintValueIsUpToDate has to call ValueSource.obtainin order to determine whether to invalidate the cache. In my use case, I have 1 particular value source which costs ~50-100ms to obtain (some external process call is involved) and there is 1 such call per project so the cost rapidly becomes noticeable. As far as I am aware ValueSource is the only option for this use case (of values sourced from an external process) .

For now, I’ve just cached the content myself to some appropriately named file (reduces the cost to <1ms which is fast enough) but are there are any strategies that can be used to avoid the call to obtain in the 1st place? I know ValueSource is designed to hide certain inputs from the cache but I suppose my use case is a value that is sourced from an external process but where the returned values are entirely dependent on the input parameters.

Afair only by not getting the value of the value source at configuration time.
If you need the value at configuration time, well, how should it be determined without calling obtain?

the particular use case is a function but one that requires an external process call (hence the inputs are sufficient to know the cached value is accurate)

Well, Gradle cannot know that.
How should it know whether the external call would always return the same value for the same inputs?
How should it even know that an external call is done?
Even without an external call, how should it know that the implementation is always returning the same value for the same inputs?

That’s exactly the contract of a value source.
Gradle provides the inputs and checks what output you calculated in the implementation of the value source.

Actually, what you are after is ValueSource/Provider caching based on inputs · Issue #31908 · gradle/gradle · GitHub :slight_smile:

1 Like

Yes exactly, the linked memoized feature would also be useful

1 Like