-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Make param.depends efficient #927
Comments
Enabling cache with |
Caching |
@MarcSkovMadsen can you quantify how inefficient |
I mean class Adder(param.Parameterized):
a = param.Number()
b = param.Number()
@param.depends('a', 'b')
def result(self):
return self.a+self.b you write: class Adder(param.Parameterized):
a = param.Number()
b = param.Number()
result = param.Number()
@param.depends('a', 'b', watch=True)
def _calculate(self):
self.result = self.a+self.b When using |
Agree with Philipp. The main problem is that the bound functions are called the same number of times as you depend on them instead of one time. The examples I provided are the same as Philipp provided. Philipp second example look simple, but if you start having multiple parameters to update it becomes less obvious what goes on. I think its friction that you have to write that extra boiler plate code in every Parameterized class you write instead of just providing a |
I don't buy the argument of having state that is not-depended on. Right now without concrete examples I believe that is an antipattern. Pro adding caching I would also argue that
|
Its becoming more and more clear to me just how inefficient param.depends and param.bind are if you want to depend on them multiple times.
Thus I suggested at HoloViz meeting that for Panel that we start recommending
pn.rx(some_func)(args,...)
overpn.bind(some_func, args...)
because the end usage is the same. But the pn.rx version is much more efficient. But the feedback was thatpn.rx
was not yet well enough understood.As an alternative I would suggest making
pn.depends
(andpn.bind
) more efficient by caching results similar to whatpn.rx
does.One more argument is that Panel tutorials promotes creating more advanced applications with the DataStore design pattern. And this also promotes depending multiple times on references. The tutorial uses
pn.rx
. I don't know if Philipp did it for efficiency reasons or just because he could? But usingparam.depends
withoutwatch=True
would have led to an inefficient application https://panel.holoviz.org/tutorials/intermediate/structure_data_store.html.Example
The below example shows how inefficient it is to depend on a
param.depends
annotated function multiple times.inefficient.mp4
As you can see, you can avoid the inefficiency by using
watch=True
and updating named parameters. But this makes your code much longer and much more complicated.The text was updated successfully, but these errors were encountered: