Skip to content

Commit

Permalink
[lib] Run conversion only on state check
Browse files Browse the repository at this point in the history
Summary:
[ENG-4524](https://linear.app/comm/issue/ENG-4524/performance-downgrade-on-the-web-app)
The id schema conversion for the state check was run everytime selector needed to be rerun, even when it wasn't necessary (e.g. navigating between threads). This diff changes it to so that the conversion is run only when the state check is requested from the keyserver.

Test Plan:
- Checked that the state check still runs correctly
- Can't reproduce the performance problem on my machine (too small redux) but checked the performance graph in the browser when navigating between threads:
Before the changes:
{F661658}
After the changes:
{F661638}
You can see that the conversion doesn't run.

For comparison here's the graph for the current master:
{F661688}
The highlighted `Cn` function is the id schema conversion function

Reviewers: kamil, tomek, ashoat

Reviewed By: kamil, ashoat

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D8649
  • Loading branch information
MichalGniadek committed Jul 28, 2023
1 parent fa412e6 commit 9158eb6
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions lib/selectors/socket-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,6 @@ const getClientResponsesSelector: (
currentUserInfo: ?CurrentUserInfo,
calendarQuery: (calendarActive: boolean) => CalendarQuery,
) => {
threadInfos = convertClientIDsToServerIDs(
ashoatKeyserverID,
t.dict(tID, rawThreadInfoValidator),
threadInfos,
);
userInfos = convertClientIDsToServerIDs(
ashoatKeyserverID,
userInfosValidator,
userInfos,
);
currentUserInfo = convertClientIDsToServerIDs(
ashoatKeyserverID,
t.maybe(currentUserInfoValidator),
currentUserInfo,
);

return async (
calendarActive: boolean,
oneTimeKeyGenerator: ?OneTimeKeyGenerator,
Expand All @@ -116,42 +100,60 @@ const getClientResponsesSelector: (
platformDetails: getConfig().platformDetails,
});
} else if (serverRequest.type === serverRequestTypes.CHECK_STATE) {
let filteredEntryInfos = filterRawEntryInfosByCalendarQuery(
const filteredEntryInfos = filterRawEntryInfosByCalendarQuery(
serverEntryInfosObject(values(entryInfos)),
calendarQuery(calendarActive),
);

filteredEntryInfos = convertClientIDsToServerIDs(
const convertedEntryInfos = convertClientIDsToServerIDs(
ashoatKeyserverID,
t.dict(tID, rawEntryInfoValidator),
filteredEntryInfos,
);

const convertedThreadInfos = convertClientIDsToServerIDs(
ashoatKeyserverID,
t.dict(tID, rawThreadInfoValidator),
threadInfos,
);

const convertedUserInfos = convertClientIDsToServerIDs(
ashoatKeyserverID,
userInfosValidator,
userInfos,
);

const convertedCurrentUserInfo = convertClientIDsToServerIDs(
ashoatKeyserverID,
t.maybe(currentUserInfoValidator),
currentUserInfo,
);

const hashResults = {};
for (const key in serverRequest.hashesToCheck) {
const expectedHashValue = serverRequest.hashesToCheck[key];
let hashValue;
if (key === 'threadInfos') {
hashValue = hash(threadInfos);
hashValue = hash(convertedThreadInfos);
} else if (key === 'entryInfos') {
hashValue = hash(filteredEntryInfos);
hashValue = hash(convertedEntryInfos);
} else if (key === 'userInfos') {
hashValue = hash(userInfos);
hashValue = hash(convertedUserInfos);
} else if (key === 'currentUserInfo') {
hashValue = hash(currentUserInfo);
hashValue = hash(convertedCurrentUserInfo);
} else if (key.startsWith('threadInfo|')) {
const [, threadID] = key.split('|');
hashValue = hash(threadInfos[threadID]);
hashValue = hash(convertedThreadInfos[threadID]);
} else if (key.startsWith('entryInfo|')) {
const [, entryID] = key.split('|');
let rawEntryInfo = filteredEntryInfos[entryID];
let rawEntryInfo = convertedEntryInfos[entryID];
if (rawEntryInfo) {
rawEntryInfo = serverEntryInfo(rawEntryInfo);
}
hashValue = hash(rawEntryInfo);
} else if (key.startsWith('userInfo|')) {
const [, userID] = key.split('|');
hashValue = hash(userInfos[userID]);
hashValue = hash(convertedUserInfos[userID]);
} else {
continue;
}
Expand All @@ -160,7 +162,7 @@ const getClientResponsesSelector: (

const { failUnmentioned } = serverRequest;
if (failUnmentioned && failUnmentioned.threadInfos) {
for (const threadID in threadInfos) {
for (const threadID in convertedThreadInfos) {
const key = `threadInfo|${threadID}`;
const hashResult = hashResults[key];
if (hashResult === null || hashResult === undefined) {
Expand All @@ -169,7 +171,7 @@ const getClientResponsesSelector: (
}
}
if (failUnmentioned && failUnmentioned.entryInfos) {
for (const entryID in filteredEntryInfos) {
for (const entryID in convertedEntryInfos) {
const key = `entryInfo|${entryID}`;
const hashResult = hashResults[key];
if (hashResult === null || hashResult === undefined) {
Expand All @@ -178,7 +180,7 @@ const getClientResponsesSelector: (
}
}
if (failUnmentioned && failUnmentioned.userInfos) {
for (const userID in userInfos) {
for (const userID in convertedUserInfos) {
const key = `userInfo|${userID}`;
const hashResult = hashResults[key];
if (hashResult === null || hashResult === undefined) {
Expand Down

0 comments on commit 9158eb6

Please sign in to comment.