this calls three functions — setupPerformancePublisher, startDirtyTaskTracking, startLongPipelineTracking.
startDirtyTaskTracking and startLongPipelineTracking are defined in the same event-tracking.ts file except for the setupPerformancePublisher which is imported from core/notifications/performance.ts.
If there is one thing that I noticed, it is the cleanup involved across the react-scan codebase to avoid memory leaks.
const onComplete = async ( _: string, finalInteraction: FinalInteraction, event: PerformanceEntryChannelEvent, ) => { toolbarEventStore.getState().actions.addEvent({ kind: 'interaction', id: not_globally_unique_generateId(), data: { startAt: finalInteraction.detailedTiming.blockingTimeStart, endAt: performance.now() + performance.timeOrigin, meta: { ...finalInteraction, kind: event.kind }, // TODO, will need interaction specific metadata here }, }); const existingCompletedInteractions = performanceEntryChannels.getChannelState('recording'); finalInteraction.detailedTiming.stopListeningForRenders(); if (existingCompletedInteractions.length) { // then performance entry and our detailed timing handlers are out of sync, we disregard that entry // it may be possible the performance entry returned before detailed timing. If that's the case we should update // assumptions and deal with mapping the entry back to the detailed timing here performanceEntryChannels.updateChannelState( 'recording', () => new BoundedArray(MAX_CHANNEL_SIZE), ); } };
this onComplete arrow function is defined in startTimingTracking. There’s an “interaction” event added and then there is this comment explaining what that if block is about:
// then performance entry and our detailed timing handlers are out of sync, we disregard that entry// it may be possible the performance entry returned before detailed timing. If that's the case we should update// assumptions and deal with mapping the entry back to the detailed timing here
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.