@@ -239,12 +239,28 @@ const ProfileMetricsGraph = ({
239239 if ( response ?. series != null ) {
240240 // Check if user wants ALL series for THIS specific response
241241 const userWantsAllForThisResponse = showAllSeriesForResponse === response ;
242+ const maxSeriesLimit = 100 ;
243+
244+ // Limit the number of series to maxSeriesLimit to avoid performance issues (unless user opts to show all)
245+ if ( response . series . length > maxSeriesLimit && ! userWantsAllForThisResponse ) {
246+ // Select top `maxSeriesLimit` series based on their max value (to catch series with large spikes)
247+ const seriesWithMaxValue = response . series . map ( series => {
248+ const maxValue = series . samples . reduce ( ( max , sample ) => {
249+ const value = sample . valuePerSecond ?? 0 ;
250+ return value > max ? value : max ;
251+ } , 0 ) ;
252+ return { series, maxValue} ;
253+ } ) ;
254+
255+ // Sort by max value descending and take top `maxSeriesLimit` series
256+ const topSeries = seriesWithMaxValue
257+ . sort ( ( a , b ) => b . maxValue - a . maxValue )
258+ . slice ( 0 , maxSeriesLimit )
259+ . map ( item => item . series ) ;
242260
243- // Limit the number of series to 100 to avoid performance issues (unless user opts to show all)
244- if ( response . series . length > 100 && ! userWantsAllForThisResponse ) {
245261 return [
246- response . series . slice ( 0 , 100 ) ,
247- { isTrimmed : true , beforeTrim : response . series . length , afterTrim : 100 } ,
262+ topSeries ,
263+ { isTrimmed : true , beforeTrim : response . series . length , afterTrim : maxSeriesLimit } ,
248264 ] ;
249265 }
250266 return [ response . series , { isTrimmed : false , beforeTrim : 0 , afterTrim : 0 } ] ;
0 commit comments