Skip to content

Add profiling marks to React #5

@taneliang

Description

@taneliang

Steps

  • Add a enableSchedulingProfiler feature flag.
  • Add user timing marks and measures wherever DebugTracing is used. Follow the prototype DataTracing User Timing API calls.
  • Add tests similar to the ones for 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 using Scheduler.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 work Lanes 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 from getCurrentPriorityLevel 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 from inferPriorityFromExpirationTime, which has no analog in the lane implementation. Questions:

    • Why can't the log*UpdateScheduled callers also use the priority levels from getCurrentPriorityLevel?
    • If we can't, what should we do? Is there a way to compute a Lane's LanePriority? 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#19142

  • Brian 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

  1. If enableSchedulingProfiler is true:
    1. User event marks should be generated, following facebook/react@master...bvaughn:root-event-marks (ignoring renderAbandoned as DebugTracing does not have that).
  2. Else no change to existing behavior.

Tests should be written.

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions