Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit cdb0c24

Browse files
committed
Add temporary timing functions to old RoomListStore
1 parent b608c69 commit cdb0c24

File tree

1 file changed

+52
-8
lines changed

1 file changed

+52
-8
lines changed

src/stores/RoomListStore.js

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,27 @@ export const ALGO_RECENT = "recent";
5858

5959
const CATEGORY_ORDER = [CATEGORY_RED, CATEGORY_GREY, CATEGORY_BOLD, CATEGORY_IDLE];
6060

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) {
6282
// apply manual sorting only to m.favourite, otherwise respect the global setting
6383
// all the known tags are listed explicitly here to simplify future changes
6484
switch (listKey) {
@@ -73,7 +93,7 @@ const getListAlgorithm = (listKey, settingAlgorithm) => {
7393
default: // custom-tags
7494
return ALGO_MANUAL;
7595
}
76-
};
96+
}
7797

7898
const knownLists = new Set([
7999
"m.favourite",
@@ -340,6 +360,7 @@ class RoomListStore extends Store {
340360
}
341361

342362
_getRecommendedTagsForRoom(room) {
363+
const timerId = startTimer(`_getRecommendedTagsForRoom(room:"${room.roomId}")`);
343364
const tags = [];
344365

345366
const myMembership = room.getMyMembership();
@@ -365,11 +386,12 @@ class RoomListStore extends Store {
365386
tags.push("im.vector.fake.archived");
366387
}
367388

368-
389+
endTimer(timerId);
369390
return tags;
370391
}
371392

372393
_slotRoomIntoList(room, category, tag, existingEntries, newList, lastTimestampFn) {
394+
const timerId = startTimer(`_slotRoomIntoList(room:"${room.roomId}", "${category}", "${tag}", existingEntries: "${existingEntries.length}", "${newList}", lastTimestampFn:"${lastTimestampFn !== null}")`);
373395
const targetCategoryIndex = CATEGORY_ORDER.indexOf(category);
374396

375397
let categoryComparator = (a, b) => lastTimestampFn(a.room) >= lastTimestampFn(b.room);
@@ -481,11 +503,16 @@ class RoomListStore extends Store {
481503
pushedEntry = true;
482504
}
483505

506+
endTimer(timerId);
484507
return pushedEntry;
485508
}
486509

487510
_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+
}
489516

490517
const listsClone = {};
491518

@@ -582,9 +609,11 @@ class RoomListStore extends Store {
582609
}
583610

584611
this._setState({lists: listsClone});
612+
endTimer(timerId);
585613
}
586614

587615
_generateInitialRoomLists() {
616+
const timerId = startTimer(`_generateInitialRoomLists()`);
588617
// Log something to show that we're throwing away the old results. This is for the inevitable
589618
// question of "why is 100% of my CPU going towards Riot?" - a quick look at the logs would reveal
590619
// that something is wrong with the RoomListStore.
@@ -697,6 +726,7 @@ class RoomListStore extends Store {
697726
lists,
698727
ready: true, // Ready to receive updates to ordering
699728
});
729+
endTimer(timerId);
700730
}
701731

702732
_eventTriggersRecentReorder(ev) {
@@ -709,7 +739,9 @@ class RoomListStore extends Store {
709739
_tsOfNewestEvent(room) {
710740
// Apparently we can have rooms without timelines, at least under testing
711741
// 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+
}
713745

714746
for (let i = room.timeline.length - 1; i >= 0; --i) {
715747
const ev = room.timeline[i];
@@ -729,23 +761,35 @@ class RoomListStore extends Store {
729761
}
730762

731763
_calculateCategory(room) {
764+
const timerId = startTimer(`_calculateCategory(room:"${room.roomId}")`);
732765
if (!this._state.orderImportantFirst) {
733766
// Effectively disable the categorization of rooms if we're supposed to
734767
// be sorting by more recent messages first. This triggers the timestamp
735768
// comparison bit of _setRoomCategory and _recentsComparator instead of
736769
// the category ordering.
770+
endTimer(timerId);
737771
return CATEGORY_IDLE;
738772
}
739773

740774
const mentions = room.getUnreadNotificationCount("highlight") > 0;
741-
if (mentions) return CATEGORY_RED;
775+
if (mentions) {
776+
endTimer(timerId);
777+
return CATEGORY_RED;
778+
}
742779

743780
let unread = room.getUnreadNotificationCount() > 0;
744-
if (unread) return CATEGORY_GREY;
781+
if (unread) {
782+
endTimer(timerId);
783+
return CATEGORY_GREY;
784+
}
745785

746786
unread = Unread.doesRoomHaveUnreadMessages(room);
747-
if (unread) return CATEGORY_BOLD;
787+
if (unread) {
788+
endTimer(timerId);
789+
return CATEGORY_BOLD;
790+
}
748791

792+
endTimer(timerId);
749793
return CATEGORY_IDLE;
750794
}
751795

0 commit comments

Comments
 (0)