Skip to content

perf(): Remove inside onChange event #229

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

Merged
merged 1 commit into from
Jan 13, 2016

Conversation

elifer5000
Copy link

When the callback run while changing the slider takes a certain amount of time (~50 ms or more), the
inside onChange can stall resulting in many changes lost along the way while it catches up.
Removing seems to have no visible side effects. It might be possible that this is due to
scope.() being called right before callOnChange(), so the model is updated anyway (see in
applyModel)

See:
http://jsfiddle.net/c8po9y58/3/

Move the slider like crazy and watch the console output, you will see no stalling. To compare use the master version:
http://jsfiddle.net/3bfnocrb/1/

@codecov-io
Copy link

Current coverage is 100.00%

Merging #229 into master will not affect coverage as of e4d660d

@@            master    #229   diff @@
======================================
  Files            1       1       
  Stmts          622     620     -2
  Branches         0       0       
  Methods          0       0       
======================================
- Hit            622     620     -2
  Partial          0       0       
  Missed           0       0       

Review entire Coverage Diff as of e4d660d

Powered by Codecov. Updated on successful CI builds.

@ValentinH
Copy link
Member

OK now I understand the issue. :)
Indeed, in the applyModel method we already call scope.$apply() so this $timeout is useless and bring overhead.

I think I'll also remove the $timeout call for the onStart since it should be called right away. However, I'll keep it for the onEnd since we need to ensure that the model is synchronized.

@@ -817,9 +817,7 @@
callOnChange: function() {
if (this.options.onChange) {
var self = this;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make it perfect, could you remove this line and call onChange directly on this? (When it's done, don't forget to rebase so there is one commit) ;)

When the callback run while changing the slider takes a certain amount of time (~50 ms or more), the
 inside onChange can stall resulting in many changes lost along the way while it catches up.
Removing seems to have no visible side effects. It might be possible that this is due to
scope.() being called right before callOnChange(), so the model is updated anyway (see in
applyModel)
@elifer5000
Copy link
Author

Ok, done!

@ValentinH
Copy link
Member

Great thanks.

ValentinH added a commit that referenced this pull request Jan 13, 2016
perf(): Remove $timeout call inside onChange event
@ValentinH ValentinH merged commit c73e0e7 into angular-slider:master Jan 13, 2016
@ValentinH
Copy link
Member

I just rollback your changes to the callback logic because I found the reason why we needed to wrap them in a $timeout call: if the user was changing one of its scope values in the callback function, then its changed wouldn't be applied.

In the new version, I replaced the previous $timeout calls by $evalAsync one.

See you example with the latest version: http://jsfiddle.net/zb33necv/ . Everything seems OK to me.

@elifer5000
Copy link
Author

I see, will the performance be the same, though?

On Sun, Jan 24, 2016 at 1:00 PM, Valentin Hervieu [email protected]
wrote:

I just rollback your changes to the callback logic because I found the
reason why we needed to wrap them in a $timeout call: if the user was
changing one of its scope values in the callback function, then its changed
wouldn't be applied.

In the new version, I replaced the previous $timeout calls by $evalAsync
one.


Reply to this email directly or view it on GitHub
#229 (comment)
.

@ValentinH
Copy link
Member

If I understand correctly how it works, with $evalAsync, if there is already a digest in progress then it will be executed in it, otherwise it will program a new one.

@elifer5000
Copy link
Author

Indeed it seems to be ok. I tried again with my same sample and there's no
dropped events. You can try it here:
http://jsfiddle.net/3bfnocrb/2/

On Tue, Jan 26, 2016 at 9:07 AM, Valentin Hervieu [email protected]
wrote:

If I understand correctly how it works, with $evalAsync, if there is
already a digest in progress then it will be executed in it, otherwise it
will program a new one.


Reply to this email directly or view it on GitHub
#229 (comment)
.

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

Successfully merging this pull request may close these issues.

3 participants