Revert "Add temporary timing functions to old RoomListStore"

This reverts commit 82b55ffd77.
This commit is contained in:
Travis Ralston 2020-03-12 13:34:56 -06:00
parent 5cfe29de66
commit 21e471375e

View file

@ -58,27 +58,7 @@ export const ALGO_RECENT = "recent";
const CATEGORY_ORDER = [CATEGORY_RED, CATEGORY_GREY, CATEGORY_BOLD, CATEGORY_IDLE]; const CATEGORY_ORDER = [CATEGORY_RED, CATEGORY_GREY, CATEGORY_BOLD, CATEGORY_IDLE];
function debugLog(...msg) { const getListAlgorithm = (listKey, settingAlgorithm) => {
console.log(`[RoomListStore:Debug] `, ...msg);
}
const timers = {};
let timerCounter = 0;
function startTimer(fnName) {
const id = `${fnName}_${(new Date()).getTime()}_${timerCounter++}`;
debugLog(`Started timer for ${fnName} with ID ${id}`);
timers[id] = {start: (new Date()).getTime(), fnName};
return id;
}
function endTimer(id) {
const timer = timers[id];
delete timers[id];
const diff = (new Date()).getTime() - timer.start;
debugLog(`${timer.fnName} took ${diff}ms (ID: ${id})`);
}
function getListAlgorithm(listKey, settingAlgorithm) {
// apply manual sorting only to m.favourite, otherwise respect the global setting // apply manual sorting only to m.favourite, otherwise respect the global setting
// all the known tags are listed explicitly here to simplify future changes // all the known tags are listed explicitly here to simplify future changes
switch (listKey) { switch (listKey) {
@ -93,7 +73,7 @@ function getListAlgorithm(listKey, settingAlgorithm) {
default: // custom-tags default: // custom-tags
return ALGO_MANUAL; return ALGO_MANUAL;
} }
} };
const knownLists = new Set([ const knownLists = new Set([
"m.favourite", "m.favourite",
@ -377,7 +357,6 @@ class RoomListStore extends Store {
} }
_getRecommendedTagsForRoom(room) { _getRecommendedTagsForRoom(room) {
const timerId = startTimer(`_getRecommendedTagsForRoom(room:"${room.roomId}")`);
const tags = []; const tags = [];
const myMembership = room.getMyMembership(); const myMembership = room.getMyMembership();
@ -403,12 +382,11 @@ class RoomListStore extends Store {
tags.push("im.vector.fake.archived"); tags.push("im.vector.fake.archived");
} }
endTimer(timerId);
return tags; return tags;
} }
_slotRoomIntoList(room, category, tag, existingEntries, newList, lastTimestampFn) { _slotRoomIntoList(room, category, tag, existingEntries, newList, lastTimestampFn) {
const timerId = startTimer(`_slotRoomIntoList(room:"${room.roomId}", "${category}", "${tag}", existingEntries: "${existingEntries.length}", "${newList}", lastTimestampFn:"${lastTimestampFn !== null}")`);
const targetCategoryIndex = CATEGORY_ORDER.indexOf(category); const targetCategoryIndex = CATEGORY_ORDER.indexOf(category);
let categoryComparator = (a, b) => lastTimestampFn(a.room) >= lastTimestampFn(b.room); let categoryComparator = (a, b) => lastTimestampFn(a.room) >= lastTimestampFn(b.room);
@ -520,16 +498,11 @@ class RoomListStore extends Store {
pushedEntry = true; pushedEntry = true;
} }
endTimer(timerId);
return pushedEntry; return pushedEntry;
} }
_setRoomCategory(room, category) { _setRoomCategory(room, category) {
const timerId = startTimer(`_setRoomCategory(room:"${room.roomId}", "${category}")`); if (!room) return; // This should only happen in tests
if (!room) {
endTimer(timerId);
return; // This should only happen in tests
}
const listsClone = {}; const listsClone = {};
@ -626,11 +599,9 @@ class RoomListStore extends Store {
} }
this._setState({lists: listsClone}); this._setState({lists: listsClone});
endTimer(timerId);
} }
_generateInitialRoomLists() { _generateInitialRoomLists() {
const timerId = startTimer(`_generateInitialRoomLists()`);
// Log something to show that we're throwing away the old results. This is for the inevitable // Log something to show that we're throwing away the old results. This is for the inevitable
// question of "why is 100% of my CPU going towards Riot?" - a quick look at the logs would reveal // question of "why is 100% of my CPU going towards Riot?" - a quick look at the logs would reveal
// that something is wrong with the RoomListStore. // that something is wrong with the RoomListStore.
@ -743,7 +714,6 @@ class RoomListStore extends Store {
lists, lists,
ready: true, // Ready to receive updates to ordering ready: true, // Ready to receive updates to ordering
}); });
endTimer(timerId);
} }
_eventTriggersRecentReorder(ev) { _eventTriggersRecentReorder(ev) {
@ -756,9 +726,7 @@ class RoomListStore extends Store {
_tsOfNewestEvent(room) { _tsOfNewestEvent(room) {
// Apparently we can have rooms without timelines, at least under testing // Apparently we can have rooms without timelines, at least under testing
// environments. Just return MAX_INT when this happens. // environments. Just return MAX_INT when this happens.
if (!room || !room.timeline) { if (!room || !room.timeline) return Number.MAX_SAFE_INTEGER;
return Number.MAX_SAFE_INTEGER;
}
for (let i = room.timeline.length - 1; i >= 0; --i) { for (let i = room.timeline.length - 1; i >= 0; --i) {
const ev = room.timeline[i]; const ev = room.timeline[i];
@ -778,35 +746,23 @@ class RoomListStore extends Store {
} }
_calculateCategory(room) { _calculateCategory(room) {
const timerId = startTimer(`_calculateCategory(room:"${room.roomId}")`);
if (!this._state.orderImportantFirst) { if (!this._state.orderImportantFirst) {
// Effectively disable the categorization of rooms if we're supposed to // Effectively disable the categorization of rooms if we're supposed to
// be sorting by more recent messages first. This triggers the timestamp // be sorting by more recent messages first. This triggers the timestamp
// comparison bit of _setRoomCategory and _recentsComparator instead of // comparison bit of _setRoomCategory and _recentsComparator instead of
// the category ordering. // the category ordering.
endTimer(timerId);
return CATEGORY_IDLE; return CATEGORY_IDLE;
} }
const mentions = room.getUnreadNotificationCount("highlight") > 0; const mentions = room.getUnreadNotificationCount("highlight") > 0;
if (mentions) { if (mentions) return CATEGORY_RED;
endTimer(timerId);
return CATEGORY_RED;
}
let unread = room.getUnreadNotificationCount() > 0; let unread = room.getUnreadNotificationCount() > 0;
if (unread) { if (unread) return CATEGORY_GREY;
endTimer(timerId);
return CATEGORY_GREY;
}
unread = Unread.doesRoomHaveUnreadMessages(room); unread = Unread.doesRoomHaveUnreadMessages(room);
if (unread) { if (unread) return CATEGORY_BOLD;
endTimer(timerId);
return CATEGORY_BOLD;
}
endTimer(timerId);
return CATEGORY_IDLE; return CATEGORY_IDLE;
} }