Skip to content
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

run-loop nit-picks #18

Closed
8 tasks
stefanpenner opened this issue Feb 4, 2014 · 5 comments
Closed
8 tasks

run-loop nit-picks #18

stefanpenner opened this issue Feb 4, 2014 · 5 comments

Comments

@stefanpenner
Copy link
Collaborator

Typically code that mutates state that is managed by ember should be wrapped in a run-loop

I believe the following may not:

It seems like a firebase callback to ember-run aware promise utility method would go along way.
the following seems to be a common pattern.

So this current implementation doesn't really harness some really important aspects of ember and it's run-loop

Let me explain, with XHR it is quite common to have many some what infrequent data updates, when an update happens, we push data into the ember bindings update, observers fire, data settles, and then finally if we need to, we update the DOM.

With WebSockets, or other realtime strategies, it is quite common to have bursts of small updates. Unfortunately currently each update in these bursts will cause change propagation's, that may result in many individual DOM updates. Assuming we get 10 updates in a 50ms window, we would get 10 individual run-loop iterations and up to 10 separate DOM mutations. Interestingly, we would be forcing ember to render at rates greater then even 60FPS, which is wasteful.

In addition if these changes are coalesced into a run loop, they may cancel each other out, result in less or no DOM mutations at all.

Now the above scenario may not effect all classes of applications, but it will effect some.

One potential approach is to batch updates from firebase, and flush them to the ember managed code only at some interval. This interval may depend on the application itself and sometimes may not even be applicable.

@rlivsey
Copy link

rlivsey commented Feb 4, 2014

We handle this in fireplace with a simple event queue [1], any updates are then batched up and handled in the next run-loop. Something similar should be fairly straightforward to implement here I'd expect.

[1] https://github.com/rlivsey/fireplace/blob/master/packages/fireplace/lib/model/event_queue.js

@stefanpenner
Copy link
Collaborator Author

@rlivsey i notice a small comment in your code related to difficulty testing. Debounced/throttled workloads are a pain to test, I would suggest that firebase solution either disable itself for testing, or work it into the testing framework so it can be aware of the async

Also, your solution helps mitigate if a series of "synchronous" or near "synchronous" updates are pushed into ember, but this rate (depending on the app) can still be much higher then when a user can perceive. I would still suggest considering a solution (maybe configurable) that covers a larger window.

@anantn
Copy link
Contributor

anantn commented Feb 4, 2014

Interesting. @stefanpenner, @rlivsey - what do you suggest the default interval to push changes into Ember be? We can make it configurable of course.

@stefanpenner
Copy link
Collaborator Author

well it makes little sense to render at more then 60fps. So (1000/16)ms would be the absolute maximum, depending on the type of application and the rate of data flowing in, I have bumped it up to as high as 50ms or 100ms. But it entirely depends on what that app dictates as an acceptable latency.

@aputinski
Copy link
Collaborator

See 2a6c0ec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants