@atlaskit/editor-core 234.3.1 → 235.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/cjs/ui/quick-insert/getExtensionQuickInsertComponents.js +7 -4
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/ui/quick-insert/getExtensionQuickInsertComponents.js +6 -2
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/ui/quick-insert/getExtensionQuickInsertComponents.js +8 -5
- package/dist/esm/version-wrapper.js +1 -1
- package/package.json +43 -43
- package/dist/cjs/utils/performance/outlier.js +0 -16
- package/dist/cjs/utils/performance/percentile.js +0 -22
- package/dist/cjs/utils/performance/plugin-performance-observer.js +0 -131
- package/dist/cjs/utils/performance/plugin-performance-report.js +0 -190
- package/dist/cjs/utils/performance/simple-measure-to-entries.js +0 -101
- package/dist/es2019/utils/performance/outlier.js +0 -10
- package/dist/es2019/utils/performance/percentile.js +0 -14
- package/dist/es2019/utils/performance/plugin-performance-observer.js +0 -88
- package/dist/es2019/utils/performance/plugin-performance-report.js +0 -133
- package/dist/es2019/utils/performance/simple-measure-to-entries.js +0 -83
- package/dist/esm/utils/performance/outlier.js +0 -10
- package/dist/esm/utils/performance/percentile.js +0 -16
- package/dist/esm/utils/performance/plugin-performance-observer.js +0 -124
- package/dist/esm/utils/performance/plugin-performance-report.js +0 -183
- package/dist/esm/utils/performance/simple-measure-to-entries.js +0 -94
- package/dist/types/utils/performance/outlier.d.ts +0 -1
- package/dist/types/utils/performance/percentile.d.ts +0 -1
- package/dist/types/utils/performance/plugin-performance-observer.d.ts +0 -23
- package/dist/types/utils/performance/plugin-performance-report.d.ts +0 -47
- package/dist/types/utils/performance/simple-measure-to-entries.d.ts +0 -28
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.PluginPerformanceReport = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
-
var _outlier = require("./outlier");
|
|
13
|
-
var _trackTransactions = require("./track-transactions");
|
|
14
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
-
var PluginPerformanceReport = exports.PluginPerformanceReport = /*#__PURE__*/function () {
|
|
17
|
-
function PluginPerformanceReport(entry) {
|
|
18
|
-
var _this = this;
|
|
19
|
-
(0, _classCallCheck2.default)(this, PluginPerformanceReport);
|
|
20
|
-
(0, _defineProperty2.default)(this, "count", 0);
|
|
21
|
-
(0, _defineProperty2.default)(this, "pluginNames", []);
|
|
22
|
-
(0, _defineProperty2.default)(this, "nodes", {});
|
|
23
|
-
(0, _defineProperty2.default)(this, "extensionNodes", {});
|
|
24
|
-
(0, _defineProperty2.default)(this, "nodesDuration", 0);
|
|
25
|
-
(0, _defineProperty2.default)(this, "plugins", {});
|
|
26
|
-
(0, _defineProperty2.default)(this, "slowPlugins", {});
|
|
27
|
-
(0, _defineProperty2.default)(this, "options", {
|
|
28
|
-
samplingRate: 100,
|
|
29
|
-
slowThreshold: 300,
|
|
30
|
-
outlierThreshold: 30,
|
|
31
|
-
outlierFactor: 3
|
|
32
|
-
});
|
|
33
|
-
(0, _defineProperty2.default)(this, "isChild", function (child) {
|
|
34
|
-
return child.startTime >= _this.entry.startTime && child.startTime + child.duration <= _this.entry.startTime + _this.entry.duration;
|
|
35
|
-
});
|
|
36
|
-
this.entry = entry;
|
|
37
|
-
}
|
|
38
|
-
return (0, _createClass2.default)(PluginPerformanceReport, [{
|
|
39
|
-
key: "getEntryByName",
|
|
40
|
-
value: function getEntryByName(entryList, name) {
|
|
41
|
-
return entryList.getEntriesByName(name).find(this.isChild);
|
|
42
|
-
}
|
|
43
|
-
}, {
|
|
44
|
-
key: "getMethodSum",
|
|
45
|
-
value: function getMethodSum(methods) {
|
|
46
|
-
return Object.values(methods).reduce(function (a, b) {
|
|
47
|
-
return a + b;
|
|
48
|
-
}, 0);
|
|
49
|
-
}
|
|
50
|
-
}, {
|
|
51
|
-
key: "greaterEquals",
|
|
52
|
-
value: function greaterEquals(a, b) {
|
|
53
|
-
return typeof b === 'number' ? a >= b : false;
|
|
54
|
-
}
|
|
55
|
-
}, {
|
|
56
|
-
key: "hasOutlierMethods",
|
|
57
|
-
value: function hasOutlierMethods(methods, outliers) {
|
|
58
|
-
return this.greaterEquals(methods.stateApply, outliers.stateApplyOutlier) || this.greaterEquals(methods.viewUpdate, outliers.viewUpdateOutlier);
|
|
59
|
-
}
|
|
60
|
-
}, {
|
|
61
|
-
key: "trigger",
|
|
62
|
-
get: function get() {
|
|
63
|
-
if (this.entry.duration > this.options.slowThreshold) {
|
|
64
|
-
return 'slow';
|
|
65
|
-
} else if (this.hasSlowPlugins && this.entry.duration > this.options.outlierThreshold) {
|
|
66
|
-
return 'distribution';
|
|
67
|
-
} else if (this.count > 0 && this.count % this.options.samplingRate === 0) {
|
|
68
|
-
return 'sample';
|
|
69
|
-
} else {
|
|
70
|
-
return 'none';
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}, {
|
|
74
|
-
key: "hasSlowPlugins",
|
|
75
|
-
get: function get() {
|
|
76
|
-
return Object.keys(this.slowPlugins).length > 0;
|
|
77
|
-
}
|
|
78
|
-
}, {
|
|
79
|
-
key: "withEntryList",
|
|
80
|
-
value: function withEntryList(entryList) {
|
|
81
|
-
this.entryList = entryList;
|
|
82
|
-
this.stateApplied = this.getEntryByName(entryList, _trackTransactions.EVENT_NAME_STATE_APPLY);
|
|
83
|
-
this.viewUpdated = this.getEntryByName(entryList, _trackTransactions.EVENT_NAME_UPDATE_STATE);
|
|
84
|
-
this.onChangeCalled = this.getEntryByName(entryList, _trackTransactions.EVENT_NAME_ON_CHANGE);
|
|
85
|
-
this.onEditorViewStateUpdatedCalled = this.getEntryByName(entryList, _trackTransactions.EVENT_NAME_VIEW_STATE_UPDATED);
|
|
86
|
-
this.withPlugins(this.pluginNames);
|
|
87
|
-
return this;
|
|
88
|
-
}
|
|
89
|
-
}, {
|
|
90
|
-
key: "withPlugins",
|
|
91
|
-
value: function withPlugins(pluginNames) {
|
|
92
|
-
var _this2 = this;
|
|
93
|
-
var emptyEntry = {
|
|
94
|
-
duration: 0
|
|
95
|
-
};
|
|
96
|
-
this.pluginNames = pluginNames;
|
|
97
|
-
this.plugins = pluginNames.reduce(function (acc, name) {
|
|
98
|
-
var pluginApplied = _this2.entryList ? _this2.getEntryByName(_this2.entryList, "\uD83E\uDD89".concat(name, "::apply")) || emptyEntry : emptyEntry;
|
|
99
|
-
var pluginViewUpdated = _this2.entryList ? _this2.getEntryByName(_this2.entryList, "\uD83E\uDD89".concat(name, "::view::update")) || emptyEntry : emptyEntry;
|
|
100
|
-
var pluginOnEditorViewStateUpdated = _this2.entryList ? _this2.getEntryByName(_this2.entryList, "\uD83E\uDD89".concat(name, "::onEditorViewStateUpdated")) || emptyEntry : emptyEntry;
|
|
101
|
-
acc[name] = {
|
|
102
|
-
stateApply: pluginApplied.duration,
|
|
103
|
-
viewUpdate: pluginViewUpdated.duration,
|
|
104
|
-
onEditorViewStateUpdated: pluginOnEditorViewStateUpdated.duration
|
|
105
|
-
};
|
|
106
|
-
return acc;
|
|
107
|
-
}, {});
|
|
108
|
-
if (this.stateApplied && pluginNames.length > 0) {
|
|
109
|
-
var pluginEntries = Object.entries(this.plugins);
|
|
110
|
-
var stateApplyOutlier = (0, _outlier.outlier)(pluginEntries.map(function (_ref) {
|
|
111
|
-
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
112
|
-
stateApply = _ref2[1].stateApply;
|
|
113
|
-
return stateApply;
|
|
114
|
-
}), this.options.outlierFactor);
|
|
115
|
-
var viewUpdateOutlier = (0, _outlier.outlier)(pluginEntries.map(function (_ref3) {
|
|
116
|
-
var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
|
|
117
|
-
viewUpdate = _ref4[1].viewUpdate;
|
|
118
|
-
return viewUpdate;
|
|
119
|
-
}), this.options.outlierFactor);
|
|
120
|
-
var budget = this.options.outlierThreshold / pluginEntries.length;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Consider plugin methods slow that are
|
|
124
|
-
* statistically significantly slower than peers
|
|
125
|
-
* AND where the sum of methods for a plugin is slower than 16.7ms / plugins.length
|
|
126
|
-
*/
|
|
127
|
-
var pluginIsOutlier = function pluginIsOutlier(_ref5) {
|
|
128
|
-
var _ref6 = (0, _slicedToArray2.default)(_ref5, 2),
|
|
129
|
-
methods = _ref6[1];
|
|
130
|
-
return _this2.getMethodSum(methods) > budget && _this2.hasOutlierMethods(methods, {
|
|
131
|
-
stateApplyOutlier: stateApplyOutlier,
|
|
132
|
-
viewUpdateOutlier: viewUpdateOutlier
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
|
-
this.slowPlugins = pluginEntries.filter(pluginIsOutlier).reduce(function (acc, _ref7) {
|
|
136
|
-
var _ref8 = (0, _slicedToArray2.default)(_ref7, 2),
|
|
137
|
-
n = _ref8[0],
|
|
138
|
-
d = _ref8[1];
|
|
139
|
-
return _objectSpread(_objectSpread({}, acc), {}, (0, _defineProperty2.default)({}, n, d));
|
|
140
|
-
}, {});
|
|
141
|
-
}
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
}, {
|
|
145
|
-
key: "withNodes",
|
|
146
|
-
value: function withNodes(nodesCount) {
|
|
147
|
-
var nodesDuration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
148
|
-
this.nodes = nodesCount.nodeCount;
|
|
149
|
-
this.extensionNodes = nodesCount.extensionNodeCount;
|
|
150
|
-
this.nodesDuration = nodesDuration;
|
|
151
|
-
return this;
|
|
152
|
-
}
|
|
153
|
-
}, {
|
|
154
|
-
key: "withCount",
|
|
155
|
-
value: function withCount(count) {
|
|
156
|
-
this.count = count;
|
|
157
|
-
return this;
|
|
158
|
-
}
|
|
159
|
-
}, {
|
|
160
|
-
key: "withOptions",
|
|
161
|
-
value: function withOptions(options) {
|
|
162
|
-
Object.assign(this.options, options);
|
|
163
|
-
return this;
|
|
164
|
-
}
|
|
165
|
-
}, {
|
|
166
|
-
key: "toJSON",
|
|
167
|
-
value: function toJSON() {
|
|
168
|
-
return {
|
|
169
|
-
trigger: this.trigger,
|
|
170
|
-
duration: this.entry.duration,
|
|
171
|
-
nodes: this.nodes,
|
|
172
|
-
extensionNodes: this.extensionNodes,
|
|
173
|
-
plugins: this.plugins,
|
|
174
|
-
slowPlugins: this.slowPlugins,
|
|
175
|
-
stepDurations: {
|
|
176
|
-
stateApply: this.stateApplied ? this.stateApplied.duration : 0,
|
|
177
|
-
viewUpdate: this.viewUpdated ? this.viewUpdated.duration : 0,
|
|
178
|
-
onChange: this.onChangeCalled ? this.onChangeCalled.duration : 0,
|
|
179
|
-
onEditorViewStateUpdated: this.onEditorViewStateUpdatedCalled ? this.onEditorViewStateUpdatedCalled.duration : 0,
|
|
180
|
-
countNodes: this.nodesDuration
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
}], [{
|
|
185
|
-
key: "fromEntry",
|
|
186
|
-
value: function fromEntry(entry) {
|
|
187
|
-
return new PluginPerformanceReport(entry);
|
|
188
|
-
}
|
|
189
|
-
}]);
|
|
190
|
-
}();
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.SimpleMeasurementLogger = void 0;
|
|
8
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
-
var _trackTransactions = require("./track-transactions");
|
|
13
|
-
var EVENT_NAMES = [_trackTransactions.EVENT_NAME_STATE_APPLY, _trackTransactions.EVENT_NAME_UPDATE_STATE, _trackTransactions.EVENT_NAME_VIEW_STATE_UPDATED, _trackTransactions.EVENT_NAME_ON_CHANGE, _trackTransactions.EVENT_NAME_DISPATCH_TRANSACTION];
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A class that logs and collates measurement entries until
|
|
17
|
-
* EVENT_NAME_DISPATCHTRANSACTION is detected.
|
|
18
|
-
*
|
|
19
|
-
* At that point, it will group together all the entries
|
|
20
|
-
* logged and fire a callback with all entries packaged
|
|
21
|
-
* into a PerformanceObserverEntryList.
|
|
22
|
-
*
|
|
23
|
-
* We are able to make use of this method as the measurements
|
|
24
|
-
* which occur during dispatchTransactions are synchronous.
|
|
25
|
-
*/
|
|
26
|
-
var SimpleMeasurementLogger = exports.SimpleMeasurementLogger = /*#__PURE__*/(0, _createClass2.default)(function SimpleMeasurementLogger() {
|
|
27
|
-
var _this = this;
|
|
28
|
-
(0, _classCallCheck2.default)(this, SimpleMeasurementLogger);
|
|
29
|
-
(0, _defineProperty2.default)(this, "currentBatch", []);
|
|
30
|
-
(0, _defineProperty2.default)(this, "pluginNameCache", new Set());
|
|
31
|
-
(0, _defineProperty2.default)(this, "setPluginNames", function (names) {
|
|
32
|
-
_this.pluginNameCache = new Set(names);
|
|
33
|
-
});
|
|
34
|
-
(0, _defineProperty2.default)(this, "setOnObservation", function (callback) {
|
|
35
|
-
_this.observationCallback = callback;
|
|
36
|
-
});
|
|
37
|
-
(0, _defineProperty2.default)(this, "createPerformanceEntry", function (reading) {
|
|
38
|
-
return {
|
|
39
|
-
entryType: 'mark',
|
|
40
|
-
name: reading.name,
|
|
41
|
-
startTime: reading.startTime,
|
|
42
|
-
duration: reading.duration,
|
|
43
|
-
toJSON: function toJSON() {
|
|
44
|
-
return JSON.stringify({
|
|
45
|
-
entryType: 'mark',
|
|
46
|
-
name: reading.name,
|
|
47
|
-
startTime: reading.startTime,
|
|
48
|
-
duration: reading.duration
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
(0, _defineProperty2.default)(this, "convertToEntryList", function (batch) {
|
|
54
|
-
return {
|
|
55
|
-
getEntries: function getEntries() {
|
|
56
|
-
return batch;
|
|
57
|
-
},
|
|
58
|
-
// We ignore type because we only store type of mark in batch
|
|
59
|
-
getEntriesByName: function getEntriesByName(name, type) {
|
|
60
|
-
return batch.filter(function (entry) {
|
|
61
|
-
return entry.name === name;
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
|
-
getEntriesByType: function getEntriesByType(type) {
|
|
65
|
-
return batch;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
(0, _defineProperty2.default)(this, "observed", function (reading) {
|
|
70
|
-
// Given that this is only used for tracking transactions and
|
|
71
|
-
// transactions are synchronous, we can assume that anything measured
|
|
72
|
-
// between EVENT_NAME_DISPATCHTRANSACTION is encapsulated.
|
|
73
|
-
var name = reading.name;
|
|
74
|
-
|
|
75
|
-
// Transaction tracking event are prefixed with Owl emoji
|
|
76
|
-
if (name.startsWith('🦉')) {
|
|
77
|
-
var _name$split$;
|
|
78
|
-
// check if its logging InstrumentedPlugin.state.apply()
|
|
79
|
-
var pluginName = ((_name$split$ = name.split(':')[0]) === null || _name$split$ === void 0 ? void 0 : _name$split$.split('🦉')[1]) || '';
|
|
80
|
-
var isPluginApply = _this.pluginNameCache.has(pluginName);
|
|
81
|
-
var isTransactionMeasurement = EVENT_NAMES.includes(name);
|
|
82
|
-
if (!isTransactionMeasurement && process.env.NODE_ENV === 'development') {
|
|
83
|
-
// eslint-disable-next-line no-console
|
|
84
|
-
console.warn("SimpleMeasurementLogger: unknown transaction event name '".concat(name, "'"));
|
|
85
|
-
}
|
|
86
|
-
if (isPluginApply || isTransactionMeasurement) {
|
|
87
|
-
_this.currentBatch.push(_this.createPerformanceEntry(reading));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Trigger a report
|
|
92
|
-
if (name === _trackTransactions.EVENT_NAME_DISPATCH_TRANSACTION) {
|
|
93
|
-
// convert the batch into a bunch of entries
|
|
94
|
-
if (_this.observationCallback) {
|
|
95
|
-
var _entries = _this.convertToEntryList((0, _toConsumableArray2.default)(_this.currentBatch));
|
|
96
|
-
_this.observationCallback(_entries);
|
|
97
|
-
}
|
|
98
|
-
_this.currentBatch = [];
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { percentile } from './percentile';
|
|
2
|
-
export const outlier = (input, factor) => {
|
|
3
|
-
const q1 = percentile(input, 0.25);
|
|
4
|
-
const q3 = percentile(input, 0.75);
|
|
5
|
-
if (typeof q1 === 'undefined' || typeof q3 === 'undefined') {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
const iqr = q3 - q1;
|
|
9
|
-
return q3 + iqr * factor;
|
|
10
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export const percentile = (input, fraction) => {
|
|
2
|
-
const sorted = input.sort((a, b) => a - b);
|
|
3
|
-
const position = sorted.length * fraction;
|
|
4
|
-
const base = Math.floor(position);
|
|
5
|
-
const rest = position - base;
|
|
6
|
-
if (rest > 0) {
|
|
7
|
-
return sorted[base];
|
|
8
|
-
}
|
|
9
|
-
const item = sorted[base - 1];
|
|
10
|
-
const next = sorted[base];
|
|
11
|
-
if (typeof item !== 'undefined' && typeof next !== 'undefined') {
|
|
12
|
-
return (item + next) / 2;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import { PluginPerformanceReport } from './plugin-performance-report';
|
|
3
|
-
import { SimpleMeasurementLogger } from './simple-measure-to-entries';
|
|
4
|
-
import { DEFAULT_USE_PERFORMANCE_MARK, EVENT_NAME_DISPATCH_TRANSACTION } from './track-transactions';
|
|
5
|
-
export class PluginPerformanceObserver {
|
|
6
|
-
constructor(callback) {
|
|
7
|
-
_defineProperty(this, "getNodeCounts", () => [{
|
|
8
|
-
nodeCount: {},
|
|
9
|
-
extensionNodeCount: {}
|
|
10
|
-
}, 0]);
|
|
11
|
-
_defineProperty(this, "getPlugins", () => []);
|
|
12
|
-
_defineProperty(this, "getOptions", () => ({}));
|
|
13
|
-
_defineProperty(this, "reportCount", 0);
|
|
14
|
-
_defineProperty(this, "simpleObserver", new SimpleMeasurementLogger());
|
|
15
|
-
_defineProperty(this, "onObserveration", entries => {
|
|
16
|
-
const reports = entries.getEntriesByName(EVENT_NAME_DISPATCH_TRANSACTION).map(entry => PluginPerformanceReport.fromEntry(entry).withCount(++this.reportCount).withEntryList(entries).withNodes(...this.getNodeCounts()).withPlugins(this.getPlugins()).withOptions(this.getOptions()).toJSON());
|
|
17
|
-
reports.filter(report => report.trigger !== 'none').forEach(report => this.callback(report));
|
|
18
|
-
});
|
|
19
|
-
this.callback = callback;
|
|
20
|
-
this.observer = window.PerformanceObserver ? new PerformanceObserver(this.onObserveration) : {
|
|
21
|
-
observe() {},
|
|
22
|
-
disconnect() {},
|
|
23
|
-
takeRecords() {
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
get isSimpleTracking() {
|
|
29
|
-
const {
|
|
30
|
-
usePerformanceMarks = DEFAULT_USE_PERFORMANCE_MARK
|
|
31
|
-
} = this.getOptions();
|
|
32
|
-
return !usePerformanceMarks;
|
|
33
|
-
}
|
|
34
|
-
withNodeCounts(getNodeCounts) {
|
|
35
|
-
this.getNodeCounts = () => {
|
|
36
|
-
const start = performance.now();
|
|
37
|
-
const result = getNodeCounts();
|
|
38
|
-
return [result, performance.now() - start];
|
|
39
|
-
};
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
withPlugins(getPlugins) {
|
|
43
|
-
this.getPlugins = getPlugins;
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
withOptions(getOptions) {
|
|
47
|
-
this.getOptions = getOptions;
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
withTransactionTracker(getTransactionTracker) {
|
|
51
|
-
this.getTransactionTracker = getTransactionTracker;
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
observe() {
|
|
55
|
-
if (this.isSimpleTracking) {
|
|
56
|
-
this.simpleObserver.setPluginNames(this.getPlugins());
|
|
57
|
-
this.simpleObserver.setOnObservation(entries => {
|
|
58
|
-
this.onObserveration(entries, this.observer);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// can trigger a callback when stopMeasure() measures something.
|
|
62
|
-
// use that to trigger this.onObservation()
|
|
63
|
-
this.getTransactionTracker && this.getTransactionTracker().addMeasureListener(this.simpleObserver.observed);
|
|
64
|
-
} else {
|
|
65
|
-
try {
|
|
66
|
-
this.observer.observe({
|
|
67
|
-
buffered: false,
|
|
68
|
-
type: 'measure'
|
|
69
|
-
});
|
|
70
|
-
} catch (err) {
|
|
71
|
-
// Older API implementations do not support the simpler type init
|
|
72
|
-
this.observer.observe({
|
|
73
|
-
entryTypes: ['measure']
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
disconnect() {
|
|
79
|
-
if (this.isSimpleTracking) {
|
|
80
|
-
this.getTransactionTracker && this.getTransactionTracker().removeMeasureListener(this.simpleObserver.observed);
|
|
81
|
-
} else {
|
|
82
|
-
this.observer.disconnect();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
takeRecords() {
|
|
86
|
-
return this.observer.takeRecords();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import { outlier } from './outlier';
|
|
3
|
-
import { EVENT_NAME_ON_CHANGE, EVENT_NAME_STATE_APPLY, EVENT_NAME_UPDATE_STATE, EVENT_NAME_VIEW_STATE_UPDATED } from './track-transactions';
|
|
4
|
-
export class PluginPerformanceReport {
|
|
5
|
-
constructor(entry) {
|
|
6
|
-
_defineProperty(this, "count", 0);
|
|
7
|
-
_defineProperty(this, "pluginNames", []);
|
|
8
|
-
_defineProperty(this, "nodes", {});
|
|
9
|
-
_defineProperty(this, "extensionNodes", {});
|
|
10
|
-
_defineProperty(this, "nodesDuration", 0);
|
|
11
|
-
_defineProperty(this, "plugins", {});
|
|
12
|
-
_defineProperty(this, "slowPlugins", {});
|
|
13
|
-
_defineProperty(this, "options", {
|
|
14
|
-
samplingRate: 100,
|
|
15
|
-
slowThreshold: 300,
|
|
16
|
-
outlierThreshold: 30,
|
|
17
|
-
outlierFactor: 3
|
|
18
|
-
});
|
|
19
|
-
_defineProperty(this, "isChild", child => child.startTime >= this.entry.startTime && child.startTime + child.duration <= this.entry.startTime + this.entry.duration);
|
|
20
|
-
this.entry = entry;
|
|
21
|
-
}
|
|
22
|
-
static fromEntry(entry) {
|
|
23
|
-
return new PluginPerformanceReport(entry);
|
|
24
|
-
}
|
|
25
|
-
getEntryByName(entryList, name) {
|
|
26
|
-
return entryList.getEntriesByName(name).find(this.isChild);
|
|
27
|
-
}
|
|
28
|
-
getMethodSum(methods) {
|
|
29
|
-
return Object.values(methods).reduce((a, b) => a + b, 0);
|
|
30
|
-
}
|
|
31
|
-
greaterEquals(a, b) {
|
|
32
|
-
return typeof b === 'number' ? a >= b : false;
|
|
33
|
-
}
|
|
34
|
-
hasOutlierMethods(methods, outliers) {
|
|
35
|
-
return this.greaterEquals(methods.stateApply, outliers.stateApplyOutlier) || this.greaterEquals(methods.viewUpdate, outliers.viewUpdateOutlier);
|
|
36
|
-
}
|
|
37
|
-
get trigger() {
|
|
38
|
-
if (this.entry.duration > this.options.slowThreshold) {
|
|
39
|
-
return 'slow';
|
|
40
|
-
} else if (this.hasSlowPlugins && this.entry.duration > this.options.outlierThreshold) {
|
|
41
|
-
return 'distribution';
|
|
42
|
-
} else if (this.count > 0 && this.count % this.options.samplingRate === 0) {
|
|
43
|
-
return 'sample';
|
|
44
|
-
} else {
|
|
45
|
-
return 'none';
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
get hasSlowPlugins() {
|
|
49
|
-
return Object.keys(this.slowPlugins).length > 0;
|
|
50
|
-
}
|
|
51
|
-
withEntryList(entryList) {
|
|
52
|
-
this.entryList = entryList;
|
|
53
|
-
this.stateApplied = this.getEntryByName(entryList, EVENT_NAME_STATE_APPLY);
|
|
54
|
-
this.viewUpdated = this.getEntryByName(entryList, EVENT_NAME_UPDATE_STATE);
|
|
55
|
-
this.onChangeCalled = this.getEntryByName(entryList, EVENT_NAME_ON_CHANGE);
|
|
56
|
-
this.onEditorViewStateUpdatedCalled = this.getEntryByName(entryList, EVENT_NAME_VIEW_STATE_UPDATED);
|
|
57
|
-
this.withPlugins(this.pluginNames);
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
withPlugins(pluginNames) {
|
|
61
|
-
const emptyEntry = {
|
|
62
|
-
duration: 0
|
|
63
|
-
};
|
|
64
|
-
this.pluginNames = pluginNames;
|
|
65
|
-
this.plugins = pluginNames.reduce((acc, name) => {
|
|
66
|
-
const pluginApplied = this.entryList ? this.getEntryByName(this.entryList, `🦉${name}::apply`) || emptyEntry : emptyEntry;
|
|
67
|
-
const pluginViewUpdated = this.entryList ? this.getEntryByName(this.entryList, `🦉${name}::view::update`) || emptyEntry : emptyEntry;
|
|
68
|
-
const pluginOnEditorViewStateUpdated = this.entryList ? this.getEntryByName(this.entryList, `🦉${name}::onEditorViewStateUpdated`) || emptyEntry : emptyEntry;
|
|
69
|
-
acc[name] = {
|
|
70
|
-
stateApply: pluginApplied.duration,
|
|
71
|
-
viewUpdate: pluginViewUpdated.duration,
|
|
72
|
-
onEditorViewStateUpdated: pluginOnEditorViewStateUpdated.duration
|
|
73
|
-
};
|
|
74
|
-
return acc;
|
|
75
|
-
}, {});
|
|
76
|
-
if (this.stateApplied && pluginNames.length > 0) {
|
|
77
|
-
const pluginEntries = Object.entries(this.plugins);
|
|
78
|
-
const stateApplyOutlier = outlier(pluginEntries.map(([, {
|
|
79
|
-
stateApply
|
|
80
|
-
}]) => stateApply), this.options.outlierFactor);
|
|
81
|
-
const viewUpdateOutlier = outlier(pluginEntries.map(([, {
|
|
82
|
-
viewUpdate
|
|
83
|
-
}]) => viewUpdate), this.options.outlierFactor);
|
|
84
|
-
const budget = this.options.outlierThreshold / pluginEntries.length;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Consider plugin methods slow that are
|
|
88
|
-
* statistically significantly slower than peers
|
|
89
|
-
* AND where the sum of methods for a plugin is slower than 16.7ms / plugins.length
|
|
90
|
-
*/
|
|
91
|
-
const pluginIsOutlier = ([, methods]) => this.getMethodSum(methods) > budget && this.hasOutlierMethods(methods, {
|
|
92
|
-
stateApplyOutlier,
|
|
93
|
-
viewUpdateOutlier
|
|
94
|
-
});
|
|
95
|
-
this.slowPlugins = pluginEntries.filter(pluginIsOutlier).reduce((acc, [n, d]) => ({
|
|
96
|
-
...acc,
|
|
97
|
-
[n]: d
|
|
98
|
-
}), {});
|
|
99
|
-
}
|
|
100
|
-
return this;
|
|
101
|
-
}
|
|
102
|
-
withNodes(nodesCount, nodesDuration = 0) {
|
|
103
|
-
this.nodes = nodesCount.nodeCount;
|
|
104
|
-
this.extensionNodes = nodesCount.extensionNodeCount;
|
|
105
|
-
this.nodesDuration = nodesDuration;
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
withCount(count) {
|
|
109
|
-
this.count = count;
|
|
110
|
-
return this;
|
|
111
|
-
}
|
|
112
|
-
withOptions(options) {
|
|
113
|
-
Object.assign(this.options, options);
|
|
114
|
-
return this;
|
|
115
|
-
}
|
|
116
|
-
toJSON() {
|
|
117
|
-
return {
|
|
118
|
-
trigger: this.trigger,
|
|
119
|
-
duration: this.entry.duration,
|
|
120
|
-
nodes: this.nodes,
|
|
121
|
-
extensionNodes: this.extensionNodes,
|
|
122
|
-
plugins: this.plugins,
|
|
123
|
-
slowPlugins: this.slowPlugins,
|
|
124
|
-
stepDurations: {
|
|
125
|
-
stateApply: this.stateApplied ? this.stateApplied.duration : 0,
|
|
126
|
-
viewUpdate: this.viewUpdated ? this.viewUpdated.duration : 0,
|
|
127
|
-
onChange: this.onChangeCalled ? this.onChangeCalled.duration : 0,
|
|
128
|
-
onEditorViewStateUpdated: this.onEditorViewStateUpdatedCalled ? this.onEditorViewStateUpdatedCalled.duration : 0,
|
|
129
|
-
countNodes: this.nodesDuration
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import { EVENT_NAME_DISPATCH_TRANSACTION, EVENT_NAME_ON_CHANGE, EVENT_NAME_STATE_APPLY, EVENT_NAME_UPDATE_STATE, EVENT_NAME_VIEW_STATE_UPDATED } from './track-transactions';
|
|
3
|
-
const EVENT_NAMES = [EVENT_NAME_STATE_APPLY, EVENT_NAME_UPDATE_STATE, EVENT_NAME_VIEW_STATE_UPDATED, EVENT_NAME_ON_CHANGE, EVENT_NAME_DISPATCH_TRANSACTION];
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A class that logs and collates measurement entries until
|
|
7
|
-
* EVENT_NAME_DISPATCHTRANSACTION is detected.
|
|
8
|
-
*
|
|
9
|
-
* At that point, it will group together all the entries
|
|
10
|
-
* logged and fire a callback with all entries packaged
|
|
11
|
-
* into a PerformanceObserverEntryList.
|
|
12
|
-
*
|
|
13
|
-
* We are able to make use of this method as the measurements
|
|
14
|
-
* which occur during dispatchTransactions are synchronous.
|
|
15
|
-
*/
|
|
16
|
-
export class SimpleMeasurementLogger {
|
|
17
|
-
constructor() {
|
|
18
|
-
_defineProperty(this, "currentBatch", []);
|
|
19
|
-
_defineProperty(this, "pluginNameCache", new Set());
|
|
20
|
-
_defineProperty(this, "setPluginNames", names => {
|
|
21
|
-
this.pluginNameCache = new Set(names);
|
|
22
|
-
});
|
|
23
|
-
_defineProperty(this, "setOnObservation", callback => {
|
|
24
|
-
this.observationCallback = callback;
|
|
25
|
-
});
|
|
26
|
-
_defineProperty(this, "createPerformanceEntry", reading => {
|
|
27
|
-
return {
|
|
28
|
-
entryType: 'mark',
|
|
29
|
-
name: reading.name,
|
|
30
|
-
startTime: reading.startTime,
|
|
31
|
-
duration: reading.duration,
|
|
32
|
-
toJSON: () => JSON.stringify({
|
|
33
|
-
entryType: 'mark',
|
|
34
|
-
name: reading.name,
|
|
35
|
-
startTime: reading.startTime,
|
|
36
|
-
duration: reading.duration
|
|
37
|
-
})
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
_defineProperty(this, "convertToEntryList", batch => {
|
|
41
|
-
return {
|
|
42
|
-
getEntries: () => batch,
|
|
43
|
-
// We ignore type because we only store type of mark in batch
|
|
44
|
-
getEntriesByName: (name, type) => batch.filter(entry => entry.name === name),
|
|
45
|
-
getEntriesByType: type => batch
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
_defineProperty(this, "observed", reading => {
|
|
49
|
-
// Given that this is only used for tracking transactions and
|
|
50
|
-
// transactions are synchronous, we can assume that anything measured
|
|
51
|
-
// between EVENT_NAME_DISPATCHTRANSACTION is encapsulated.
|
|
52
|
-
const {
|
|
53
|
-
name
|
|
54
|
-
} = reading;
|
|
55
|
-
|
|
56
|
-
// Transaction tracking event are prefixed with Owl emoji
|
|
57
|
-
if (name.startsWith('🦉')) {
|
|
58
|
-
var _name$split$;
|
|
59
|
-
// check if its logging InstrumentedPlugin.state.apply()
|
|
60
|
-
const pluginName = ((_name$split$ = name.split(':')[0]) === null || _name$split$ === void 0 ? void 0 : _name$split$.split('🦉')[1]) || '';
|
|
61
|
-
const isPluginApply = this.pluginNameCache.has(pluginName);
|
|
62
|
-
const isTransactionMeasurement = EVENT_NAMES.includes(name);
|
|
63
|
-
if (!isTransactionMeasurement && process.env.NODE_ENV === 'development') {
|
|
64
|
-
// eslint-disable-next-line no-console
|
|
65
|
-
console.warn(`SimpleMeasurementLogger: unknown transaction event name '${name}'`);
|
|
66
|
-
}
|
|
67
|
-
if (isPluginApply || isTransactionMeasurement) {
|
|
68
|
-
this.currentBatch.push(this.createPerformanceEntry(reading));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Trigger a report
|
|
73
|
-
if (name === EVENT_NAME_DISPATCH_TRANSACTION) {
|
|
74
|
-
// convert the batch into a bunch of entries
|
|
75
|
-
if (this.observationCallback) {
|
|
76
|
-
const entries = this.convertToEntryList([...this.currentBatch]);
|
|
77
|
-
this.observationCallback(entries);
|
|
78
|
-
}
|
|
79
|
-
this.currentBatch = [];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { percentile } from './percentile';
|
|
2
|
-
export var outlier = function outlier(input, factor) {
|
|
3
|
-
var q1 = percentile(input, 0.25);
|
|
4
|
-
var q3 = percentile(input, 0.75);
|
|
5
|
-
if (typeof q1 === 'undefined' || typeof q3 === 'undefined') {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
var iqr = q3 - q1;
|
|
9
|
-
return q3 + iqr * factor;
|
|
10
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export var percentile = function percentile(input, fraction) {
|
|
2
|
-
var sorted = input.sort(function (a, b) {
|
|
3
|
-
return a - b;
|
|
4
|
-
});
|
|
5
|
-
var position = sorted.length * fraction;
|
|
6
|
-
var base = Math.floor(position);
|
|
7
|
-
var rest = position - base;
|
|
8
|
-
if (rest > 0) {
|
|
9
|
-
return sorted[base];
|
|
10
|
-
}
|
|
11
|
-
var item = sorted[base - 1];
|
|
12
|
-
var next = sorted[base];
|
|
13
|
-
if (typeof item !== 'undefined' && typeof next !== 'undefined') {
|
|
14
|
-
return (item + next) / 2;
|
|
15
|
-
}
|
|
16
|
-
};
|