@@ -54,15 +54,21 @@ export function getComputedValues<
54
54
for ( const definition of traceDefinition . computedValueDefinitions ) {
55
55
const { name, matches, computeValueFromMatches } = definition
56
56
57
- const matchingRecordedEntries = recordedItems . filter ( ( spanAndAnnotation ) =>
58
- matches . some ( ( matcher ) =>
59
- matcher ( spanAndAnnotation , { input, definition : traceDefinition } ) ,
60
- ) ,
61
- )
57
+ // Initialize arrays to hold matches for each matcher
58
+ const matchingEntriesByMatcher : SpanAndAnnotation < AllPossibleScopesT > [ ] [ ] =
59
+ Array . from ( { length : matches . length } , ( ) => [ ] )
60
+
61
+ // Single pass through recordedItems
62
+ for ( const item of recordedItems ) {
63
+ matches . forEach ( ( matcher , index ) => {
64
+ if ( matcher ( item , { input, definition : traceDefinition } ) ) {
65
+ matchingEntriesByMatcher [ index ] ! . push ( item )
66
+ }
67
+ } )
68
+ }
62
69
63
- computedValues [ name ] = computeValueFromMatches ( matchingRecordedEntries )
70
+ computedValues [ name ] = computeValueFromMatches ( ... matchingEntriesByMatcher )
64
71
}
65
-
66
72
return computedValues
67
73
}
68
74
@@ -177,21 +183,6 @@ export function getSpanSummaryAttributes<
177
183
return spanAttributes
178
184
}
179
185
180
- // IMPLEMENTATION TODO: implementation of gathering Trace level attributes
181
- export function getAttributes <
182
- TracerScopeKeysT extends KeysOfUnion < AllPossibleScopesT > ,
183
- AllPossibleScopesT ,
184
- > ( {
185
- definition,
186
- recordedItems,
187
- input,
188
- } : ComputeRecordingData < TracerScopeKeysT , AllPossibleScopesT > ) : TraceRecording <
189
- TracerScopeKeysT ,
190
- AllPossibleScopesT
191
- > [ 'attributes' ] {
192
- return { }
193
- }
194
-
195
186
function getComputedRenderBeaconSpans <
196
187
TracerScopeKeysT extends KeysOfUnion < AllPossibleScopesT > ,
197
188
AllPossibleScopesT ,
@@ -218,7 +209,14 @@ function getComputedRenderBeaconSpans<
218
209
219
210
// Group render spans by beacon and compute firstStart and lastEnd
220
211
for ( const entry of recordedItems ) {
221
- if ( entry . span . type !== 'component-render' ) continue
212
+ if (
213
+ entry . span . type !== 'component-render' &&
214
+ entry . span . type !== 'component-render-start'
215
+ ) {
216
+ // need to look at component-render-start too, because react might discard some renders as optimization
217
+ // ratio of component-render-start to component-render isn't always 1:1
218
+ continue
219
+ }
222
220
const { name, startTime, duration, scope, renderedOutput } = entry . span
223
221
// accept any span that either matches scope or doesn't share any of the scope values
224
222
const scopeMatch = scopeKeys . every (
@@ -238,19 +236,23 @@ function getComputedRenderBeaconSpans<
238
236
renderSpansByBeacon . set ( name , {
239
237
firstStart : start ,
240
238
lastEnd : contentEnd ,
241
- renderCount : 1 ,
239
+ renderCount : entry . span . type === 'component-render' ? 1 : 0 ,
242
240
sumOfDurations : duration ,
243
- firstLoadingEnd :
244
- renderedOutput === 'loading' ? start + duration : undefined ,
245
241
firstContentStart : renderedOutput === 'content' ? start : undefined ,
242
+ firstLoadingEnd :
243
+ entry . span . type === 'component-render' && renderedOutput === 'loading'
244
+ ? start + duration
245
+ : undefined ,
246
246
} )
247
247
} else {
248
248
spanTimes . firstStart = Math . min ( spanTimes . firstStart , start )
249
249
spanTimes . lastEnd =
250
250
contentEnd && spanTimes . lastEnd
251
251
? Math . max ( spanTimes . lastEnd , contentEnd )
252
252
: contentEnd ?? spanTimes . lastEnd
253
- spanTimes . renderCount += 1
253
+ if ( entry . span . type === 'component-render' ) {
254
+ spanTimes . renderCount += 1
255
+ }
254
256
spanTimes . sumOfDurations += duration
255
257
if (
256
258
spanTimes . firstContentStart === undefined &&
@@ -260,6 +262,7 @@ function getComputedRenderBeaconSpans<
260
262
}
261
263
if (
262
264
spanTimes . firstLoadingEnd === undefined &&
265
+ entry . span . type === 'component-render' &&
263
266
renderedOutput === 'loading'
264
267
) {
265
268
spanTimes . firstLoadingEnd = start + duration
0 commit comments