Perf: first-pass at reducing number of re-renders in <NextPrevKeyframeCursors>

This commit is contained in:
Aria Minaei 2022-07-12 12:10:37 +02:00 committed by Aria
parent f82c9d1155
commit b37ccb1e4e

View file

@ -185,14 +185,56 @@ export function useEditingToolsForCompoundProp<T extends SerializablePrimitive>(
} }
if (hasOneOrMoreSequencedTracks) { if (hasOneOrMoreSequencedTracks) {
const sequenceTrackId = possibleSequenceTrackIds const controlIndicators = prism.memo(
const nearbyKeyframeControls = prism.sub( `controlIndicators`,
'lcr', () => (
(): NearbyKeyframesControls => { <ControlIndicators
const sequencePosition = val( {...{
obj.sheet.getSequence().positionDerivation, pointerToProp,
obj,
possibleSequenceTrackIds,
listOfDescendantTrackIds,
}}
/>
),
[possibleSequenceTrackIds, listOfDescendantTrackIds],
) )
const ret: HasSequences = {
...common,
type: 'HasSequences',
controlIndicators,
}
return ret
} else {
return {
...common,
type: 'AllStatic',
controlIndicators: (
<DefaultOrStaticValueIndicator hasStaticOverride={false} />
),
}
}
}, [])
}
function ControlIndicators({
pointerToProp,
obj,
possibleSequenceTrackIds,
listOfDescendantTrackIds,
}: {
pointerToProp: Pointer<{}>
obj: SheetObject
possibleSequenceTrackIds: IPropPathToTrackIdTree
listOfDescendantTrackIds: SequenceTrackId[]
}) {
return usePrism(() => {
const pathToProp = getPointerParts(pointerToProp).path
const sequencePosition = val(obj.sheet.getSequence().positionDerivation)
/* /*
2/10 perf concern: 2/10 perf concern:
When displaying a hierarchy like {props: {transform: {position: {x, y, z}}}}, When displaying a hierarchy like {props: {transform: {position: {x, y, z}}}},
@ -204,11 +246,8 @@ export function useEditingToolsForCompoundProp<T extends SerializablePrimitive>(
.map((trackId) => ({ .map((trackId) => ({
trackId, trackId,
track: val( track: val(
obj.template.project.pointers.historic.sheetsById[ obj.template.project.pointers.historic.sheetsById[obj.address.sheetId]
obj.address.sheetId .sequence.tracksByObject[obj.address.objectKey].trackData[trackId],
].sequence.tracksByObject[obj.address.objectKey].trackData[
trackId
],
), ),
})) }))
.filter(({track}) => !!track) .filter(({track}) => !!track)
@ -277,12 +316,12 @@ export function useEditingToolsForCompoundProp<T extends SerializablePrimitive>(
}) })
} }
} }
return {
const pr: NearbyKeyframesControls = {
cur: hasCur cur: hasCur
? { ? {
type: 'on', type: 'on',
itemKey: itemKey: createStudioSheetItemKey.forCompoundPropAggregateKeyframe(
createStudioSheetItemKey.forCompoundPropAggregateKeyframe(
obj, obj,
pathToProp, pathToProp,
sequencePosition, sequencePosition,
@ -324,29 +363,7 @@ export function useEditingToolsForCompoundProp<T extends SerializablePrimitive>(
} }
: undefined, : undefined,
} }
},
[sequenceTrackId],
)
const nextPrevKeyframeCursors = ( return <NextPrevKeyframeCursors {...pr} />
<NextPrevKeyframeCursors {...nearbyKeyframeControls} /> }, [pointerToProp, obj, possibleSequenceTrackIds, listOfDescendantTrackIds])
)
const ret: HasSequences = {
...common,
type: 'HasSequences',
controlIndicators: nextPrevKeyframeCursors,
}
return ret
} else {
return {
...common,
type: 'AllStatic',
controlIndicators: (
<DefaultOrStaticValueIndicator hasStaticOverride={false} />
),
}
}
}, [])
} }