https://kotlinlang.org logo
Title
a

altavir

12/14/2021, 4:14 PM
modelhub[...]
Is it a good idea to use get operation for something that could be slow or accesses the disk? Or the cache is loaded in the constructor?
z

zaleslaw

12/14/2021, 5:49 PM
Good question, currently it loads model from disk or if not existed, from remote S3
a

altavir

12/14/2021, 5:50 PM
In my practice, it is a bad idea to do some potentially long operations implicitely.
z

zaleslaw

12/14/2021, 5:55 PM
Good to know, could you share some thoughts on why it's a bad idea? It's just a method call, isn't it?
a

altavir

12/14/2021, 5:58 PM
It is, but there are two things: • User does not expect a long and possibly failing code on a get method. What happens if the download request is bouncing? What happens if there is no internet connection? • For a really long process we want to have a cancelation handle. Of course it makes sense only for coroutines.
By the way, what happens if user makes a lot of get calls simultaniously?
a

Alexandre Brown

12/17/2021, 2:59 AM
If I may add. I'd personally expect a property to be idempotent and simply a return of the current state (eg
myClass.myState
, if it can be non existent then having it nullable would be expected). If we are talking about fetching something which might be cached or might not and might need a network call then I wouldn't expect that from a property since property don't support suspending. If it is a function then it is fine in my opinion since a function could be suspendable. For instance when we have
myClass.result
I wouldn't expect any computation. But when I do
myClass.getResult()
then I'm expecting a computation of some sort. If it uses the cached value, then it's fine but I'd consider that an implementation detail for the function. This is mainly backed by the fact that we tend to use property in kotlin instead of getter functions therefore when I see a get function I generally assume it represents an operation Instead of a state. This is coherent with the fact that a StateFlow has a property for the current state (which simply returns the value, no computation).
z

zaleslaw

12/17/2021, 8:13 AM
Of course, you could @Alexandre Brown, it was just an experiment and it's not the main form of access to the pretrained model from the model hub, need to revisit this approach
a

Alexandre Brown

12/17/2021, 12:01 PM
@zaleslaw I understand and my goal was just to give some perspective. I think @altavir Is right in that using the [ ] operator is usually linked to an O(1) operation therefore it would make sense to avoid any download or maybe to simply have a get function. That would looks like an easy Github issue for newbie to kotlindl like me 😄 Cheers!