Skip to content

Conversation

@brettstimmerman
Copy link
Contributor

debounce() used to return a function that when first invoked always called
clearTimeout before setTimeout, even if there was no timeout to clear.

This change adds a guard to prevent such unnecessary clearTimeout calls.
The performance implications are likely minimal, but the boolean check should
perform better in general than what amounts to a noop function call when
timeout is null. As well, devtools timelines will no longer display a
not-useful "Remove Timer" scripting blip for unnecessary clearTimeouts.

debounce() used to return a function that when first invoked always called
`clearTimeout` before `setTimeout`, even if there was no timeout to clear.

This change adds a guard to prevent such unnecessary `clearTimeout` calls.
The performance implications are likely minimal, but the boolean check should
perform better in general than what amounts to a noop function call when
`timeout` is `null`. As well, devtools timelines will no longer display a
not-useful "Remove Timer" scripting blip for unnecessary `clearTimeout`s.
angus-c added a commit that referenced this pull request Aug 26, 2014
Avoid unnecessary clearTimeouts in debounce()
@angus-c angus-c merged commit 8cbb941 into master Aug 26, 2014
@necolas necolas deleted the avoid-clearTimeout-in-debounce branch October 29, 2014 17:50
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