-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add profiling marks to React #5
Comments
@bvaughn, input needed on above when you've got a minute or 60 ☝️😃 |
@taneliang We should chat for a bit. Hopefully @jevakallio can coordinate something? I don't think I agree with some of the steps (1-3, 5). This new profiling data is not something that we are planning to expose via a programmatic API (like So a feature flag like
The
Possibly. I need to talk with Andrew/Seb about their thinking a little here to find out more. I'll report back as soon as I've got a better mental image of this. General concept is likely still the same, but the profiler UI might be a bit different.
I think a single PR makes sense for now. We can always talk about splitting up if it looks like it's too big to review.
The idea was that JavaScript that wasn't scheduled (through the scheduler API) was essentially always highest priority (because the scheduler API couldn't prioritize it to allow other things to come before it). I'm not sure how relevant that comment of mine was for the new lanes architecture though. Let me get back with info about this too. Sorry! |
Thanks @bvaughn! Also saw your comments on MLH-Fellowship/scheduling-profiler-prototype#1
Ah. In that case, should we only produce the user timing marks when the feature flag is true and, for updates/suspends, the fiber has
Understood! Though, I'd be happy to do it if you'd like me to -- it may be a good onboarding task for me as I think it'll help me understand React better.
Looking forward to hearing more about this tonight :)
👍
I think this makes sense. Thanks! |
No. We should only look to the feature flag for now- this has nothing to do with a mode, since there is no programmatic API for collecting this new data (yet) and React DevTools isn't really even involved (at least for now). The User Timing API overhead mentioned in facebook#18417 was due to the
Okay, we can talk about it today then during our meeting. |
By the way, the debug tracing feature is back in master (in the old reconciler fork) so hopefully the user timing marks work should be unblocked now. Please let me know if there are questions about the differences between the lanes impl and the old expiration time/priority impl. I think the lanes stuff is a bit easier for us, FWIW! 😄 |
Yeah! I saw the PR and I've started working on the user timing marks. Got a few more questions if you don't mind:
|
|
I see. I think the branch did serialize the component stack and the tool does parse it. Should I remove this from both React's marks and the tool then?
Cool, that makes sense. We'll mark whatever the draft branch marked ∪ whatever DebugTracing logs :)
Sounds good! |
Oh, I'd forgotten that I'd added that I guess. Short answer: Don't care too much now. Should be easy to add (or remove) later. The TODO is still not relevant since it mentions storing an ID for DevTools to retrieve later (to reduce the serialization overhead) but that assumes DevTools is running with access to the shared memory. In this case, since the new Profiler is a separate app, that TODO doesn't apply. |
High level breakdown of this commit: * Add a enableSchedulingProfiling feature flag. * Add functions that call User Timing APIs to a new SchedulingProfiler file. The file follows DebugTracing's structure. * Add user timing marks to places where DebugTracing logs. * Add user timing marks to most other places where @bvaughn's original draft DebugTracing branch marks. * Tests added * More context (and discussions with @bvaughn) available at our internal PR MLH-Fellowship#11 and issue MLH-Fellowship#5. Similar to DebugTracing, we've only added scheduling profiling calls to the old reconciler fork. Co-authored-by: Kartik Choudhary <kartik.c918@gmail.com> Co-authored-by: Kartik Choudhary <kartikc.918@gmail.com> Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
Since we are actively changing the "lanes" implementation and what the semantic value of a given lane is (e.g. facebook#19287) it would be helpful for us to encode some info in our profile that lets us match this information up later. I had been thinking about eventually encoding what the lanes ranges are, so we could display some meaningful label in the profiler, but maybe that would be a hassle and for now- we could get away with just marking the version of React the profiling data corresponds to. This would let us at least manually match the lanes up later if we wanted to dig in deeper. |
Makes sense! I'll add React version numbers to all the marks as I can't find a way to detect the start of a profile. Will using that version number of React be useful for FB's profiling data given that www is on bleeding edge versions, or is this more for users of the tool outside FB? |
I don't think we need to do that. That would bloat to the data unnecessarily 😄 Let's just add it to one of the low frequency marks, like render-scheduled? FB gets a version that's based on the git commit it was built from (e.g. "16.13.1-766af5968") so it will be fine for us too. |
This would be something we could do later, once we have tighter integration with DevTools. |
Ah yes, adding it to a low frequency mark makes more sense 😆 I don't think render-scheduled gets called after the initial page load, so I'll add it to commit-start instead? |
Hm. I guess that's a reasonable point. Render scheduled isn't called often. Generally only on page load. So I guess logging it there isn't much better than logging it on its own during module-init. Hm... that kind of sucks. We commit fairly often too and it's a little irksome to have an extra bit of data just floating along there. Maybe let's file a follow up issue for this and give it a little more thought first. |
Another possibility is to add an API to the DevTools hook that allows the profiler to ask the renderer what the priority is for a given task identifier. That way the profiler isn't coupled to any particular implementation. |
Once we get this integrated with the DevTools, that could work! I think that integration is going to be a good bit of work though. At that point, we would not need to mark the React version either, because DevTools already knows it. The one case these both fall down on is if there are multiple React (versions) on a page. Maybe we just wouldn't support that case for this profiler? |
Oh right I see, I forgot this profiler is separate from DevTools. Also even once it’s integrated you would want to encode this in the serialized log so that the data can be read back later. For stuff about the renderer that never changes, could you log that stuff once at the beginning of the profile? |
Yes, but DevTools would likely pre-process the data before exporting it, like it does with the current profiling data. So it could add metadata about the React version, lanes, etc. |
Yes, once DevTools is the thing that starts profiling. But right now you start/stop profiling with Chrome's performance tab and there's no event to listen to saying "profiling has just started" - so the only thing we could do would be to log it once at startup, during module init (as discussed above) but this only works for the reload-and-profile use case, not for a use case of doing some things and then starting profiling in the middle (which is pretty common) |
Disable parcel caching to fix tooltips
Disable parcel caching to fix tooltips
Looks like this all got finished, so I'm going to close this out. |
Steps
enableSchedulingProfiler
feature flag.DebugTracing
is used. Follow the prototype DataTracing User Timing API calls.DebugTracing
Unknowns
To Research
What effect does the reconciler/scheduler priorities actually have? If tasks are executed in the order of priority, where is this ordering/switching happening?Reconciler schedules work usingScheduler.unstable_scheduleCallback
, which registers work in a scheduling min heap. The scheduler will thus perform work based on the works' expiration dates, which are computed from the work's priority. There are also other ways to make the scheduler execute something immediately.How do the fiber lanes workLanes
bitmask stores the lanes that React is working on. >1 lane can be worked on at any one time, i.e. the lanes are "entangled", meaning that they have a dependency on each other.Blocked, need Brian
Is there existing code that generates the user timing stuff? Sounds like there is, since there's test data.Yes. Some of the user timing calls are in facebook/react@master...bvaughn:root-event-marks. Others were in React but removed in Remove Calls to User Timing API facebook/react#18417.What priorities are we using? The profiler POC and React's reconciler/scheduler have different priorities.Scheduler priorities, translated to labels in the profiler by priorityLevelToLabel. Fiber lane priorities can be translated to scheduler priorities with lanePriorityToSchedulerPriority.Will the new fiber lanes affect the priorities?DebugTracing
removed in Temporarily Remove DebugTracing from the New Reconciler facebook/react#18697, with a note saying that "Priority field on update isn't useful anymore since the lanes convey more info". The DebugTracing functions are called with priority either retrieved fromgetCurrentPriorityLevel
or have a priority level passed to it. These can still be used in the fiber lane reconciler. However,log(Force|State)UpdateScheduled
functions are called using priority levels retrieved frominferPriorityFromExpirationTime
, which has no analog in the lane implementation. Questions:Why can't thelog*UpdateScheduled
callers also use the priority levels fromgetCurrentPriorityLevel
?If we can't, what should we do? Is there a way to compute aLane
'sLanePriority
?lanePriorityToSchedulerPriority
can then convert them to scheduler priorities.We will use lanes instead of priorities.
In the same PR, "Some of the concepts are changing" -- is there anything else that will affect our profiler?We'll use lanes instead of priorities, so we will display 31 lanes instead of 4 priority rows.Should we add the DebugTracing code to the new lane reconciler first, since it's already replaced the old expiration time design in master?Done in Re-enabled DebugTracing feature for old reconciler fork facebook/react#19142Brian mentioned in the video that "new React implementation... can have multiple cooperative chunks of work per lane". Is this the new lane reconciler that Andrew is working on? If so, this sounds like we need to record the lanes the work is scheduled on instead of (or together with?) the work's React priority.No, this sounds more like the scheduler package.Eng culture: would the React team prefer us to split this into a stack of individual PRs like FB's internal Diffs, or would you rather us implement a complete feature in one PR? Seems like the latter is preferred based on past React PRs, but I wanted to make sure.
Nonblocker, but for understanding: Brian mentioned in the onboarding video that the unscheduled priority lane has things that were "scheduled outside of the scheduler API". How does that happen in a React app?
Acceptance criteria
enableSchedulingProfiler
is true:renderAbandoned
asDebugTracing
does not have that).Tests should be written.
References
The text was updated successfully, but these errors were encountered: