Skip to content

Commit

Permalink
Track performance of message sends
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Jul 30, 2021
1 parent 2d3b191 commit 0ab0971
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
13 changes: 10 additions & 3 deletions ts/components/CompositionInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ export type Props = {
): unknown;
onTextTooLong(): unknown;
onPickEmoji(o: EmojiPickDataType): unknown;
onSubmit(message: string, mentions: Array<BodyRangeType>): unknown;
onSubmit(
message: string,
mentions: Array<BodyRangeType>,
timestamp: number
): unknown;
getQuotedMessage(): unknown;
clearQuotedMessage(): unknown;
};
Expand Down Expand Up @@ -218,6 +222,7 @@ export const CompositionInput: React.ComponentType<Props> = props => {
};

const submit = () => {
const timestamp = Date.now();
const quill = quillRef.current;

if (quill === undefined) {
Expand All @@ -226,8 +231,10 @@ export const CompositionInput: React.ComponentType<Props> = props => {

const [text, mentions] = getTextAndMentions();

window.log.info(`Submitting a message with ${mentions.length} mentions`);
onSubmit(text, mentions);
window.log.info(
`CompositionInput: Submitting message ${timestamp} with ${mentions.length} mentions`
);
onSubmit(text, mentions, timestamp);
};

if (inputApi) {
Expand Down
15 changes: 14 additions & 1 deletion ts/components/conversation/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ export class Message extends React.Component<Props, State> {
}

public componentDidUpdate(prevProps: Props): void {
const { canDeleteForEveryone, isSelected } = this.props;
const { canDeleteForEveryone, isSelected, status, timestamp } = this.props;

this.startSelectedTimer();

Expand All @@ -468,6 +468,19 @@ export class Message extends React.Component<Props, State> {
if (canDeleteForEveryone !== prevProps.canDeleteForEveryone) {
this.startDeleteForEveryoneTimer();
}

if (
prevProps.status === 'sending' &&
(status === 'sent' ||
status === 'delivered' ||
status === 'read' ||
status === 'viewed')
) {
const delta = Date.now() - timestamp;
window.log.info(
`Message.tsx: Rendered 'send complete' for message ${timestamp}; took ${delta}ms`
);
}
}

public checkForHeightChange(prevProps: Props): void {
Expand Down
3 changes: 3 additions & 0 deletions ts/models/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3559,6 +3559,9 @@ export class ConversationModel extends window.Backbone
const destination = this.getSendTarget()!;
const recipients = this.getRecipients();

if (timestamp) {
window.log.info(`sendMessage: Queueing send with timestamp ${timestamp}`);
}
this.queueJob('sendMessage', async () => {
const now = timestamp || Date.now();

Expand Down
26 changes: 17 additions & 9 deletions ts/views/conversation_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,9 @@ Whisper.ConversationView = Whisper.View.extend({
this.sendStickerMessage({ packId, stickerId }),
onSubmit: (
message: string,
mentions: typeof window.Whisper.BodyRangesType
) => this.sendMessage(message, mentions),
mentions: typeof window.Whisper.BodyRangesType,
timestamp: number
) => this.sendMessage(message, mentions, { timestamp }),
onEditorStateChange: (
msg: string,
bodyRanges: Array<typeof window.Whisper.BodyRangeType>,
Expand Down Expand Up @@ -3640,7 +3641,7 @@ Whisper.ConversationView = Whisper.View.extend({
}
},

async getUntrustedContacts(options: any = {}) {
async getUntrustedContacts(options: { force?: boolean } = {}) {
const { model }: { model: ConversationModel } = this;

// This will go to the trust store for the latest identity key information,
Expand Down Expand Up @@ -3781,8 +3782,13 @@ Whisper.ConversationView = Whisper.View.extend({
return false;
},

async sendMessage(message = '', mentions = [], options = {}) {
async sendMessage(
message = '',
mentions = [],
options: { timestamp?: number; force?: boolean } = {}
) {
const { model }: { model: ConversationModel } = this;
const timestamp = options.timestamp || Date.now();

this.sendStart = Date.now();

Expand All @@ -3793,7 +3799,7 @@ Whisper.ConversationView = Whisper.View.extend({
if (contacts && contacts.length) {
const sendAnyway = await this.showSendAnywayDialog(contacts);
if (sendAnyway) {
this.sendMessage(message, mentions, { force: true });
this.sendMessage(message, mentions, { force: true, timestamp });
return;
}

Expand Down Expand Up @@ -3822,7 +3828,11 @@ Whisper.ConversationView = Whisper.View.extend({
}

const attachments = await this.getFiles();
const sendHQImages =
window.reduxStore &&
window.reduxStore.getState().composer.shouldSendHighQualityAttachments;
const sendDelta = Date.now() - this.sendStart;

window.log.info('Send pre-checks took', sendDelta, 'milliseconds');

model.sendMessage(
Expand All @@ -3833,10 +3843,8 @@ Whisper.ConversationView = Whisper.View.extend({
undefined, // sticker
mentions,
{
sendHQImages:
window.reduxStore &&
window.reduxStore.getState().composer
.shouldSendHighQualityAttachments,
sendHQImages,
timestamp,
}
);

Expand Down

0 comments on commit 0ab0971

Please sign in to comment.