@@ -58,7 +58,27 @@ export const ALGO_RECENT = "recent";
58
58
59
59
const CATEGORY_ORDER = [ CATEGORY_RED , CATEGORY_GREY , CATEGORY_BOLD , CATEGORY_IDLE ] ;
60
60
61
- const getListAlgorithm = ( listKey , settingAlgorithm ) => {
61
+ function debugLog ( ...msg ) {
62
+ console . log ( `[RoomListStore:Debug] ` , ...msg ) ;
63
+ }
64
+
65
+ const timers = { } ;
66
+ let timerCounter = 0 ;
67
+ function startTimer ( fnName ) {
68
+ const id = `${ fnName } _${ ( new Date ( ) ) . getTime ( ) } _${ timerCounter ++ } ` ;
69
+ debugLog ( `Started timer for ${ fnName } with ID ${ id } ` ) ;
70
+ timers [ id ] = { start : ( new Date ( ) ) . getTime ( ) , fnName} ;
71
+ return id ;
72
+ }
73
+
74
+ function endTimer ( id ) {
75
+ const timer = timers [ id ] ;
76
+ delete timers [ id ] ;
77
+ const diff = ( new Date ( ) ) . getTime ( ) - timer . start ;
78
+ debugLog ( `${ timer . fnName } took ${ diff } ms (ID: ${ id } )` ) ;
79
+ }
80
+
81
+ function getListAlgorithm ( listKey , settingAlgorithm ) {
62
82
// apply manual sorting only to m.favourite, otherwise respect the global setting
63
83
// all the known tags are listed explicitly here to simplify future changes
64
84
switch ( listKey ) {
@@ -73,7 +93,7 @@ const getListAlgorithm = (listKey, settingAlgorithm) => {
73
93
default : // custom-tags
74
94
return ALGO_MANUAL ;
75
95
}
76
- } ;
96
+ }
77
97
78
98
const knownLists = new Set ( [
79
99
"m.favourite" ,
@@ -340,6 +360,7 @@ class RoomListStore extends Store {
340
360
}
341
361
342
362
_getRecommendedTagsForRoom ( room ) {
363
+ const timerId = startTimer ( `_getRecommendedTagsForRoom(room:"${ room . roomId } ")` ) ;
343
364
const tags = [ ] ;
344
365
345
366
const myMembership = room . getMyMembership ( ) ;
@@ -365,11 +386,12 @@ class RoomListStore extends Store {
365
386
tags . push ( "im.vector.fake.archived" ) ;
366
387
}
367
388
368
-
389
+ endTimer ( timerId ) ;
369
390
return tags ;
370
391
}
371
392
372
393
_slotRoomIntoList ( room , category , tag , existingEntries , newList , lastTimestampFn ) {
394
+ const timerId = startTimer ( `_slotRoomIntoList(room:"${ room . roomId } ", "${ category } ", "${ tag } ", existingEntries: "${ existingEntries . length } ", "${ newList } ", lastTimestampFn:"${ lastTimestampFn !== null } ")` ) ;
373
395
const targetCategoryIndex = CATEGORY_ORDER . indexOf ( category ) ;
374
396
375
397
let categoryComparator = ( a , b ) => lastTimestampFn ( a . room ) >= lastTimestampFn ( b . room ) ;
@@ -481,11 +503,16 @@ class RoomListStore extends Store {
481
503
pushedEntry = true ;
482
504
}
483
505
506
+ endTimer ( timerId ) ;
484
507
return pushedEntry ;
485
508
}
486
509
487
510
_setRoomCategory ( room , category ) {
488
- if ( ! room ) return ; // This should only happen in tests
511
+ const timerId = startTimer ( `_setRoomCategory(room:"${ room . roomId } ", "${ category } ")` ) ;
512
+ if ( ! room ) {
513
+ endTimer ( timerId ) ;
514
+ return ; // This should only happen in tests
515
+ }
489
516
490
517
const listsClone = { } ;
491
518
@@ -582,9 +609,11 @@ class RoomListStore extends Store {
582
609
}
583
610
584
611
this . _setState ( { lists : listsClone } ) ;
612
+ endTimer ( timerId ) ;
585
613
}
586
614
587
615
_generateInitialRoomLists ( ) {
616
+ const timerId = startTimer ( `_generateInitialRoomLists()` ) ;
588
617
// Log something to show that we're throwing away the old results. This is for the inevitable
589
618
// question of "why is 100% of my CPU going towards Riot?" - a quick look at the logs would reveal
590
619
// that something is wrong with the RoomListStore.
@@ -697,6 +726,7 @@ class RoomListStore extends Store {
697
726
lists,
698
727
ready : true , // Ready to receive updates to ordering
699
728
} ) ;
729
+ endTimer ( timerId ) ;
700
730
}
701
731
702
732
_eventTriggersRecentReorder ( ev ) {
@@ -709,7 +739,9 @@ class RoomListStore extends Store {
709
739
_tsOfNewestEvent ( room ) {
710
740
// Apparently we can have rooms without timelines, at least under testing
711
741
// environments. Just return MAX_INT when this happens.
712
- if ( ! room || ! room . timeline ) return Number . MAX_SAFE_INTEGER ;
742
+ if ( ! room || ! room . timeline ) {
743
+ return Number . MAX_SAFE_INTEGER ;
744
+ }
713
745
714
746
for ( let i = room . timeline . length - 1 ; i >= 0 ; -- i ) {
715
747
const ev = room . timeline [ i ] ;
@@ -729,23 +761,35 @@ class RoomListStore extends Store {
729
761
}
730
762
731
763
_calculateCategory ( room ) {
764
+ const timerId = startTimer ( `_calculateCategory(room:"${ room . roomId } ")` ) ;
732
765
if ( ! this . _state . orderImportantFirst ) {
733
766
// Effectively disable the categorization of rooms if we're supposed to
734
767
// be sorting by more recent messages first. This triggers the timestamp
735
768
// comparison bit of _setRoomCategory and _recentsComparator instead of
736
769
// the category ordering.
770
+ endTimer ( timerId ) ;
737
771
return CATEGORY_IDLE ;
738
772
}
739
773
740
774
const mentions = room . getUnreadNotificationCount ( "highlight" ) > 0 ;
741
- if ( mentions ) return CATEGORY_RED ;
775
+ if ( mentions ) {
776
+ endTimer ( timerId ) ;
777
+ return CATEGORY_RED ;
778
+ }
742
779
743
780
let unread = room . getUnreadNotificationCount ( ) > 0 ;
744
- if ( unread ) return CATEGORY_GREY ;
781
+ if ( unread ) {
782
+ endTimer ( timerId ) ;
783
+ return CATEGORY_GREY ;
784
+ }
745
785
746
786
unread = Unread . doesRoomHaveUnreadMessages ( room ) ;
747
- if ( unread ) return CATEGORY_BOLD ;
787
+ if ( unread ) {
788
+ endTimer ( timerId ) ;
789
+ return CATEGORY_BOLD ;
790
+ }
748
791
792
+ endTimer ( timerId ) ;
749
793
return CATEGORY_IDLE ;
750
794
}
751
795
0 commit comments