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

Enable synchronously toggling experimental addUserTimingListener #11812

Closed
jsdf opened this issue Dec 8, 2017 · 3 comments
Closed

Enable synchronously toggling experimental addUserTimingListener #11812

jsdf opened this issue Dec 8, 2017 · 3 comments

Comments

@jsdf
Copy link
Contributor

jsdf commented Dec 8, 2017

Currently ReactInternals.addUserTimingListener enables logging to the User Timing API inside a setTimeout.
However, for the use case of building a profiling tool where instrumentation is turned off most
of the time to avoid overhead, then randomly turned on for a period to take a sample, it would be ideal to be able to enable this logging synchronously (eg. turn it on at the start of a callstack and turn it off again at the end of the synchronous stack).

This is complicated by the fact that the enabled state of the logging should not be toggled inside a React callstack. As the profiler would have control over when the toggling happens, I think it would be fine to throw an error/return false/something like that if the logging was toggled while inside a React stack, allowing the profiler to try again later.

In fact, if the toggling was synchronous the profiler cp avoid this error by doing the toggling at the start and end of an event handler/setTimeout/reqAnimFrame etc which would ensure that we are not inside synchronous call into React (though I'm not quite sure what the implications of Fiber are here; would React async rendering mean that we could re-enter from the event loop at a time when this toggling should not happen?).

Alternatively the toggling could happen 'async but just later in the same React stack' (like setState). In this case the code requesting the toggling would probably need some kind of callback to know that toggling happened so it can keep track of whether React's logging is on or off. However this variant seems like it would be more complicated to implement, and for our use case I don't think it's any more useful than having the toggling just fail in a recoverable way.

cc @gaearon

@gaearon
Copy link
Collaborator

gaearon commented Dec 8, 2017

though I'm not quite sure what the implications of Fiber are here; would React async rendering mean that we could re-enter from the event loop at a time when this toggling should not happen

I think it could re-enter from requestAnimationFrame, requestIdleCallback, or setTimeout. (Depends on how we implement the polyfill.)

@gaearon
Copy link
Collaborator

gaearon commented Aug 9, 2018

Seems like the interaction tracking thing @bvaughn is building might be a better fit in the longer term.

@gaearon gaearon closed this as completed Aug 9, 2018
@bvaughn
Copy link
Contributor

bvaughn commented Aug 9, 2018

Some related links ^

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

No branches or pull requests

3 participants