Fork me on GitHub
#re-frame
<
2017-09-24
>
sandbags07:09:02

@yury.solovyov if i understand you correctly what you are saying is that you would like to ignore changes to the database that occur within a specific interval, i.e. debouncing updates

sandbags07:09:02

my inclination would be to think about this at the other end of the pipe in the events that change the database

sandbags07:09:34

where you could either ignore events that occur within a certain time delta or use :dispatch-later to requeue them

sandbags07:09:23

probably you're going to end up with a solution along the lines of dispatch-later that coalesces updates so you do eventutally process something but don't get a bunch of changes all at once

yury.solovyov09:09:24

@reefersleep @sandbags No, I can't ignore the events. They are all important. The thing is that I was doing premature optimization. I profiled the thing and it is not bad at all, so I've actually left it as is.

reefersleep09:09:38

@yury.solovyov good! I wonder if what I suggested works the way I think, that is - "normal" subscriptions fire every time the db changes, since they take it as an arg whereas (I hope) the computational part of the subscriptions above only fires when the dependent parts of the db change. And whether this could have helped you, if the computation had indeed been your processing bottleneck.

yury.solovyov09:09:20

In the profile, the hot part was destructuring event maps actually, which is kinda reasonable, since I have lots of them

yury.solovyov10:09:39

I didn't actually understand at the point you mentioned layer 3 subscription how is it going to help, but now they you've mentioned recomputation condition, I'll take another look

reefersleep12:09:02

My (now outdated, but bear with me) understanding of your problem was that in one of your subscription fns, you had an expensive computation. Since all subscription fns are run every time the db changes, this was causing performance issues in your app. My proposed solution was to create a subscription fn which is dependent not on the entire db, but only those parts which is interested in. These (supposedly simple) parts are captured in different subscriptions, which are run every time the db changes. However, since the computational part is only interested in the value that the simple subscriptions return, it will only be run every time one of those simple fns returns a new value.

reefersleep12:09:56

I just tried checking out re-frame and running that todomvc sample, added a prn to sorted-todos:

(defn sorted-todos
  [db _]
  (prn "running sorted-todos")
  (:todos db))
and one to to the :todos computational fn:
(fn [sorted-todos query-v _]
    (prn "running todos")
    (vals sorted-todos))
And as I expected, the former is printed every time anything changes in the db, whereas the latter is only printed whenever the returned value of the subscription it depends on changes πŸ™‚

yury.solovyov12:09:13

not sure if it is better for perf, but probably better for soul πŸ™‚

reefersleep12:09:54

Me neither, honestly πŸ™‚ I suppose so.

reefersleep12:09:04

I’m planning to do it that way for all my future stuff, anyway

reefersleep12:09:00

to soothe my soul

reefersleep12:09:18

did you notice the sugar in the bottom of the todomvc example?

reefersleep12:09:04

oh, my bad, I guess that doesn’t apply for your use case, since your query is parametrized

yury.solovyov12:09:59

yea, I have same within a couple lines above

yury.solovyov12:09:10

(reg-sub :copy-info
  :<- [:from-to] ;dependency
  (fn [[from-panel to-panel]]
    {
      :from-path (from-panel :current-path)
      :to-path (to-panel :current-path)
      :selection (from-panel :selection)
    }))

yury.solovyov12:09:46

I wish I had more of these, since they seem more pure and idiomatic, but I'm still learning and re-writing things all the time

reefersleep12:09:33

πŸ™‚ me too