@atlaskit/editor-core 234.3.1 → 234.3.2

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