Commit 14b09730 authored by Thomas Randolph's avatar Thomas Randolph

Add performance instrumentation to MR Diffs app

- When adding the diffs event hub, also rename the 
existing hub in the actions to notesEventHub
parent cc8057b7
...@@ -20,6 +20,8 @@ import HiddenFilesWarning from './hidden_files_warning.vue'; ...@@ -20,6 +20,8 @@ import HiddenFilesWarning from './hidden_files_warning.vue';
import MergeConflictWarning from './merge_conflict_warning.vue'; import MergeConflictWarning from './merge_conflict_warning.vue';
import CollapsedFilesWarning from './collapsed_files_warning.vue'; import CollapsedFilesWarning from './collapsed_files_warning.vue';
import { diffsApp } from '../utils/performance';
import { import {
TREE_LIST_WIDTH_STORAGE_KEY, TREE_LIST_WIDTH_STORAGE_KEY,
INITIAL_TREE_WIDTH, INITIAL_TREE_WIDTH,
...@@ -272,8 +274,12 @@ export default { ...@@ -272,8 +274,12 @@ export default {
); );
} }
}, },
beforeCreate() {
diffsApp.instrument();
},
created() { created() {
this.adjustView(); this.adjustView();
eventHub.$once('fetchDiffData', this.fetchData); eventHub.$once('fetchDiffData', this.fetchData);
eventHub.$on('refetchDiffData', this.refetchDiffData); eventHub.$on('refetchDiffData', this.refetchDiffData);
this.CENTERED_LIMITED_CONTAINER_CLASSES = CENTERED_LIMITED_CONTAINER_CLASSES; this.CENTERED_LIMITED_CONTAINER_CLASSES = CENTERED_LIMITED_CONTAINER_CLASSES;
...@@ -294,6 +300,8 @@ export default { ...@@ -294,6 +300,8 @@ export default {
); );
}, },
beforeDestroy() { beforeDestroy() {
diffsApp.deinstrument();
eventHub.$off('fetchDiffData', this.fetchData); eventHub.$off('fetchDiffData', this.fetchData);
eventHub.$off('refetchDiffData', this.refetchDiffData); eventHub.$off('refetchDiffData', this.refetchDiffData);
this.removeEventListeners(); this.removeEventListeners();
...@@ -487,9 +495,11 @@ export default { ...@@ -487,9 +495,11 @@ export default {
<div v-if="isBatchLoading" class="loading"><gl-loading-icon size="lg" /></div> <div v-if="isBatchLoading" class="loading"><gl-loading-icon size="lg" /></div>
<template v-else-if="renderDiffFiles"> <template v-else-if="renderDiffFiles">
<diff-file <diff-file
v-for="file in diffs" v-for="(file, index) in diffs"
:key="file.newPath" :key="file.newPath"
:file="file" :file="file"
:is-first-file="index === 0"
:is-last-file="index === diffs.length - 1"
:help-page-path="helpPagePath" :help-page-path="helpPagePath"
:can-current-user-fork="canCurrentUserFork" :can-current-user-fork="canCurrentUserFork"
:view-diffs-file-by-file="viewDiffsFileByFile" :view-diffs-file-by-file="viewDiffsFileByFile"
......
...@@ -15,6 +15,8 @@ import { ...@@ -15,6 +15,8 @@ import {
DIFF_FILE_AUTOMATIC_COLLAPSE, DIFF_FILE_AUTOMATIC_COLLAPSE,
DIFF_FILE_MANUAL_COLLAPSE, DIFF_FILE_MANUAL_COLLAPSE,
EVT_EXPAND_ALL_FILES, EVT_EXPAND_ALL_FILES,
EVT_PERF_MARK_DIFF_FILES_END,
EVT_PERF_MARK_FIRST_DIFF_FILE_SHOWN,
} from '../constants'; } from '../constants';
import { DIFF_FILE, GENERIC_ERROR } from '../i18n'; import { DIFF_FILE, GENERIC_ERROR } from '../i18n';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
...@@ -35,6 +37,16 @@ export default { ...@@ -35,6 +37,16 @@ export default {
type: Object, type: Object,
required: true, required: true,
}, },
isFirstFile: {
type: Boolean,
required: false,
default: false,
},
isLastFile: {
type: Boolean,
required: false,
default: false,
},
canCurrentUserFork: { canCurrentUserFork: {
type: Boolean, type: Boolean,
required: true, required: true,
...@@ -160,6 +172,11 @@ export default { ...@@ -160,6 +172,11 @@ export default {
notesEventHub.$on(`loadCollapsedDiff/${this.file.file_hash}`, this.requestDiff); notesEventHub.$on(`loadCollapsedDiff/${this.file.file_hash}`, this.requestDiff);
eventHub.$on(EVT_EXPAND_ALL_FILES, this.expandAllListener); eventHub.$on(EVT_EXPAND_ALL_FILES, this.expandAllListener);
}, },
async mounted() {
if (this.hasDiff) {
await this.postRender();
}
},
beforeDestroy() { beforeDestroy() {
eventHub.$off(EVT_EXPAND_ALL_FILES, this.expandAllListener); eventHub.$off(EVT_EXPAND_ALL_FILES, this.expandAllListener);
}, },
...@@ -175,6 +192,23 @@ export default { ...@@ -175,6 +192,23 @@ export default {
this.handleToggle(); this.handleToggle();
} }
}, },
async postRender() {
const eventsForThisFile = [];
if (this.isFirstFile) {
eventsForThisFile.push(EVT_PERF_MARK_FIRST_DIFF_FILE_SHOWN);
}
if (this.isLastFile) {
eventsForThisFile.push(EVT_PERF_MARK_DIFF_FILES_END);
}
await this.$nextTick();
eventsForThisFile.forEach(event => {
eventHub.$emit(event);
});
},
handleToggle() { handleToggle() {
const currentCollapsedFlag = this.isCollapsed; const currentCollapsedFlag = this.isCollapsed;
...@@ -197,7 +231,8 @@ export default { ...@@ -197,7 +231,8 @@ export default {
}) })
.then(() => { .then(() => {
requestIdleCallback( requestIdleCallback(
() => { async () => {
await this.postRender();
this.assignDiscussionsToDiff(this.getDiffFileDiscussions(this.file)); this.assignDiscussionsToDiff(this.getDiffFileDiscussions(this.file));
}, },
{ timeout: 1000 }, { timeout: 1000 },
......
...@@ -8,7 +8,8 @@ import { __, s__ } from '~/locale'; ...@@ -8,7 +8,8 @@ import { __, s__ } from '~/locale';
import { handleLocationHash, historyPushState, scrollToElement } from '~/lib/utils/common_utils'; import { handleLocationHash, historyPushState, scrollToElement } from '~/lib/utils/common_utils';
import { mergeUrlParams, getLocationHash } from '~/lib/utils/url_utility'; import { mergeUrlParams, getLocationHash } from '~/lib/utils/url_utility';
import TreeWorker from '../workers/tree_worker'; import TreeWorker from '../workers/tree_worker';
import eventHub from '../../notes/event_hub'; import notesEventHub from '../../notes/event_hub';
import eventHub from '../event_hub';
import { import {
getDiffPositionByLineCode, getDiffPositionByLineCode,
getNoteFormData, getNoteFormData,
...@@ -42,6 +43,9 @@ import { ...@@ -42,6 +43,9 @@ import {
NO_SHOW_WHITESPACE, NO_SHOW_WHITESPACE,
DIFF_FILE_MANUAL_COLLAPSE, DIFF_FILE_MANUAL_COLLAPSE,
DIFF_FILE_AUTOMATIC_COLLAPSE, DIFF_FILE_AUTOMATIC_COLLAPSE,
EVT_PERF_MARK_FILE_TREE_START,
EVT_PERF_MARK_FILE_TREE_END,
EVT_PERF_MARK_DIFF_FILES_START,
} from '../constants'; } from '../constants';
import { diffViewerModes } from '~/ide/constants'; import { diffViewerModes } from '~/ide/constants';
import { isCollapsed } from '../diff_file'; import { isCollapsed } from '../diff_file';
...@@ -78,6 +82,7 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { ...@@ -78,6 +82,7 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => {
commit(types.SET_BATCH_LOADING, true); commit(types.SET_BATCH_LOADING, true);
commit(types.SET_RETRIEVING_BATCHES, true); commit(types.SET_RETRIEVING_BATCHES, true);
eventHub.$emit(EVT_PERF_MARK_DIFF_FILES_START);
const getBatch = (page = 1) => const getBatch = (page = 1) =>
axios axios
...@@ -139,9 +144,11 @@ export const fetchDiffFilesMeta = ({ commit, state }) => { ...@@ -139,9 +144,11 @@ export const fetchDiffFilesMeta = ({ commit, state }) => {
}; };
commit(types.SET_LOADING, true); commit(types.SET_LOADING, true);
eventHub.$emit(EVT_PERF_MARK_FILE_TREE_START);
worker.addEventListener('message', ({ data }) => { worker.addEventListener('message', ({ data }) => {
commit(types.SET_TREE_DATA, data); commit(types.SET_TREE_DATA, data);
eventHub.$emit(EVT_PERF_MARK_FILE_TREE_END);
worker.terminate(); worker.terminate();
}); });
...@@ -215,7 +222,7 @@ export const assignDiscussionsToDiff = ( ...@@ -215,7 +222,7 @@ export const assignDiscussionsToDiff = (
} }
Vue.nextTick(() => { Vue.nextTick(() => {
eventHub.$emit('scrollToDiscussion'); notesEventHub.$emit('scrollToDiscussion');
}); });
}; };
...@@ -240,7 +247,7 @@ export const renderFileForDiscussionId = ({ commit, rootState, state }, discussi ...@@ -240,7 +247,7 @@ export const renderFileForDiscussionId = ({ commit, rootState, state }, discussi
} }
if (file.viewer.automaticallyCollapsed) { if (file.viewer.automaticallyCollapsed) {
eventHub.$emit(`loadCollapsedDiff/${file.file_hash}`); notesEventHub.$emit(`loadCollapsedDiff/${file.file_hash}`);
scrollToElement(document.getElementById(file.file_hash)); scrollToElement(document.getElementById(file.file_hash));
} else if (file.viewer.manuallyCollapsed) { } else if (file.viewer.manuallyCollapsed) {
commit(types.SET_FILE_COLLAPSED, { commit(types.SET_FILE_COLLAPSED, {
...@@ -248,9 +255,9 @@ export const renderFileForDiscussionId = ({ commit, rootState, state }, discussi ...@@ -248,9 +255,9 @@ export const renderFileForDiscussionId = ({ commit, rootState, state }, discussi
collapsed: false, collapsed: false,
trigger: DIFF_FILE_AUTOMATIC_COLLAPSE, trigger: DIFF_FILE_AUTOMATIC_COLLAPSE,
}); });
eventHub.$emit('scrollToDiscussion'); notesEventHub.$emit('scrollToDiscussion');
} else { } else {
eventHub.$emit('scrollToDiscussion'); notesEventHub.$emit('scrollToDiscussion');
} }
} }
} }
...@@ -485,7 +492,7 @@ export const setShowWhitespace = ({ commit }, { showWhitespace, pushState = fals ...@@ -485,7 +492,7 @@ export const setShowWhitespace = ({ commit }, { showWhitespace, pushState = fals
historyPushState(mergeUrlParams({ w }, window.location.href)); historyPushState(mergeUrlParams({ w }, window.location.href));
} }
eventHub.$emit('refetchDiffData'); notesEventHub.$emit('refetchDiffData');
}; };
export const toggleFileFinder = ({ commit }, visible) => { export const toggleFileFinder = ({ commit }, visible) => {
......
import { performanceMarkAndMeasure } from '~/performance_utils'; import { performanceMarkAndMeasure } from '~/performance/utils';
import { import {
MR_DIFFS_MARK_FILE_TREE_START, MR_DIFFS_MARK_FILE_TREE_START,
MR_DIFFS_MARK_FILE_TREE_END, MR_DIFFS_MARK_FILE_TREE_END,
...@@ -7,7 +7,7 @@ import { ...@@ -7,7 +7,7 @@ import {
MR_DIFFS_MARK_DIFF_FILES_END, MR_DIFFS_MARK_DIFF_FILES_END,
MR_DIFFS_MEASURE_FILE_TREE_DONE, MR_DIFFS_MEASURE_FILE_TREE_DONE,
MR_DIFFS_MEASURE_DIFF_FILES_DONE, MR_DIFFS_MEASURE_DIFF_FILES_DONE,
} from '../../performance_constants'; } from '../../performance/constants';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
import { import {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment