Commit 8f78da10 authored by Denys Mishunov's avatar Denys Mishunov

Simplified performance util

- We accept only one mark instead of Array
- Got rid of unnecessary performanceMark() utility function
parent fa5ed6f9
...@@ -11,7 +11,7 @@ import { ...@@ -11,7 +11,7 @@ import {
WEBIDE_MEASURE_FILE_FROM_REQUEST, WEBIDE_MEASURE_FILE_FROM_REQUEST,
WEBIDE_MEASURE_FILE_AFTER_INTERACTION, WEBIDE_MEASURE_FILE_AFTER_INTERACTION,
} from '~/performance_constants'; } from '~/performance_constants';
import { performanceMeasureAfterRendering } from '~/performance_utils'; import { performanceMarkAndMeasure } from '~/performance_utils';
import { modalTypes } from '../constants'; import { modalTypes } from '../constants';
import eventHub from '../eventhub'; import eventHub from '../eventhub';
import FindFile from '~/vue_shared/components/file_finder/index.vue'; import FindFile from '~/vue_shared/components/file_finder/index.vue';
...@@ -26,11 +26,11 @@ import CommitEditorHeader from './commit_sidebar/editor_header.vue'; ...@@ -26,11 +26,11 @@ import CommitEditorHeader from './commit_sidebar/editor_header.vue';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
const markPerformance = params => { const markPerformance = params => {
performanceMeasureAfterRendering(params); performanceMarkAndMeasure(params);
}; };
const markTreePerformance = () => { const markTreePerformance = () => {
markPerformance({ markPerformance({
marks: [WEBIDE_MARK_TREE_FINISH], mark: WEBIDE_MARK_TREE_FINISH,
measures: [ measures: [
{ {
name: WEBIDE_MEASURE_TREE_FROM_REQUEST, name: WEBIDE_MEASURE_TREE_FROM_REQUEST,
...@@ -42,7 +42,7 @@ const markTreePerformance = () => { ...@@ -42,7 +42,7 @@ const markTreePerformance = () => {
}; };
const markEditorLoadPerformance = () => { const markEditorLoadPerformance = () => {
markPerformance({ markPerformance({
marks: [WEBIDE_MARK_FILE_FINISH], mark: WEBIDE_MARK_FILE_FINISH,
measures: [ measures: [
{ {
name: WEBIDE_MEASURE_FILE_FROM_REQUEST, name: WEBIDE_MEASURE_FILE_FROM_REQUEST,
...@@ -54,7 +54,7 @@ const markEditorLoadPerformance = () => { ...@@ -54,7 +54,7 @@ const markEditorLoadPerformance = () => {
}; };
const markEditorInteractionPerformance = () => { const markEditorInteractionPerformance = () => {
markPerformance({ markPerformance({
marks: [WEBIDE_MARK_FILE_FINISH], mark: WEBIDE_MARK_FILE_FINISH,
measures: [ measures: [
{ {
name: WEBIDE_MEASURE_FILE_AFTER_INTERACTION, name: WEBIDE_MEASURE_FILE_AFTER_INTERACTION,
......
...@@ -7,7 +7,7 @@ import { ...@@ -7,7 +7,7 @@ import {
WEBIDE_MEASURE_TREE_FROM_REQUEST, WEBIDE_MEASURE_TREE_FROM_REQUEST,
WEBIDE_MARK_FILE_CLICKED, WEBIDE_MARK_FILE_CLICKED,
} from '~/performance_constants'; } from '~/performance_constants';
import { performanceMark } from '~/performance_utils'; import { performanceMarkAndMeasure } from '~/performance_utils';
import eventHub from '../eventhub'; import eventHub from '../eventhub';
import IdeFileRow from './ide_file_row.vue'; import IdeFileRow from './ide_file_row.vue';
import NavDropdown from './nav_dropdown.vue'; import NavDropdown from './nav_dropdown.vue';
...@@ -33,7 +33,7 @@ export default { ...@@ -33,7 +33,7 @@ export default {
}, },
}, },
beforeCreate() { beforeCreate() {
performanceMark(WEBIDE_MARK_TREE_START); performanceMarkAndMeasure({ mark: WEBIDE_MARK_TREE_START });
}, },
updated() { updated() {
if (this.currentTree?.tree?.length) { if (this.currentTree?.tree?.length) {
...@@ -45,7 +45,7 @@ export default { ...@@ -45,7 +45,7 @@ export default {
methods: { methods: {
...mapActions(['toggleTreeOpen']), ...mapActions(['toggleTreeOpen']),
clickedFile() { clickedFile() {
performanceMark(WEBIDE_MARK_FILE_CLICKED); performanceMarkAndMeasure({ mark: WEBIDE_MARK_FILE_CLICKED });
}, },
}, },
IdeFileRow, IdeFileRow,
......
...@@ -10,7 +10,7 @@ import { ...@@ -10,7 +10,7 @@ import {
WEBIDE_MEASURE_FILE_AFTER_INTERACTION, WEBIDE_MEASURE_FILE_AFTER_INTERACTION,
WEBIDE_MEASURE_FILE_FROM_REQUEST, WEBIDE_MEASURE_FILE_FROM_REQUEST,
} from '~/performance_constants'; } from '~/performance_constants';
import { performanceMark } from '~/performance_utils'; import { performanceMarkAndMeasure } from '~/performance_utils';
import eventHub from '../eventhub'; import eventHub from '../eventhub';
import { import {
leftSidebarViews, leftSidebarViews,
...@@ -173,7 +173,7 @@ export default { ...@@ -173,7 +173,7 @@ export default {
}, },
}, },
beforeCreate() { beforeCreate() {
performanceMark(WEBIDE_MARK_FILE_START); performanceMarkAndMeasure({ mark: WEBIDE_MARK_FILE_START });
}, },
beforeDestroy() { beforeDestroy() {
this.editor.dispose(); this.editor.dispose();
......
const processMeasures = measures => { export const performanceMarkAndMeasure = ({ mark, measures = [] } = {}) => {
measures.forEach(measure => {
window.requestAnimationFrame(() =>
performance.measure(measure.name, measure.start, measure.end),
);
});
};
export const performanceMeasureAfterRendering = ({ marks = [], measures = [] } = {}) => {
window.requestAnimationFrame(() => { window.requestAnimationFrame(() => {
if (marks.length) { if (mark && !performance.getEntriesByName(mark).length) {
marks.forEach(mark => { performance.mark(mark);
if (!performance.getEntriesByName(mark).length) {
performance.mark(mark);
processMeasures(measures);
}
});
} else {
processMeasures(measures);
} }
}); measures.forEach(measure => {
}; window.requestAnimationFrame(() =>
export const performanceMark = mark => { performance.measure(measure.name, measure.start, measure.end),
window.requestAnimationFrame(() => { );
performance.mark(mark); });
}); });
}; };
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