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

Patch globals #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Patch globals #1

wants to merge 1 commit into from

Conversation

kriskowal
Copy link

I altered Chronos to patch the global timers since this would permit it to be used as a drop-in performance improvement.

However, in my particular application, Chronos adds a second to a one-second process, whereas my setTimeout patch shaves off 100ms. It might be good to talk about use cases. Mine in particular is exclusively using setTimeout 0.

https://gist.github.com/910806

var keys = typeof Object.keys === "function"
? Object.keys
: function (obj) {
var ks = [], k;
for ( k in obj ) {
if ( obj.hasOwnProperty(k) ) {
if ( hasOwnProperty.call(k) ) {
Copy link
Owner

Choose a reason for hiding this comment

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

Am I missing something or should this line be hasOwnProperty.call(obj, k)?

@fitzgen
Copy link
Owner

fitzgen commented Apr 12, 2011

Hey Kris! Thanks for the pull request!

The goals of chronos and the snippet that I saw from you on Twitter the other day are slightly different, but I thought we used similar techniques so I thought you would be interested. As you mention, your goal is to make 0 timeouts and intervals possible. The goal of chronos, on the other hand, is to prevent against "timer congestion" as I discuss in my blog post: http://fitzgeraldnick.com/weblog/40/

One of the trade offs that chronos makes to do this is to push back timers if the browser isn't responsive. So code isn't necessarily more efficient or performant, however it should make the browser seem more responsive to user input. That said, if your application is experienceing delays of a whole second, then you can try setting the minimum interval lower with chronos.minimumInterval(25). If that doesn't help, I think you may have run in to a bug, and I would love to get a smaller example which could reproduce it. Let me know if this helps at all.

Also, see my inline comment above.

Lastly, I think it probably best not to override the globals by default. I will mess with the code so that there is a function something like chronos.patchGlobals().

@fitzgen
Copy link
Owner

fitzgen commented Apr 12, 2011

I pushed my updates to your code to this branch, do you want to pull them in to your fork so they are associated with this pull request?

Basically, just pulled out the patching of the globals to an optional function and added a test for it. Also, I added the obj parameter to the call to hasOwnProperty, since I assume that was a little bug (correct me if I am wrong).

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.

2 participants