@contrail/util 1.1.15-alpha-9 → 1.1.15-alpha-11
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/lib/performance-util/example-usage.js +3 -3
- package/lib/performance-util/performance-util.d.ts +7 -7
- package/lib/performance-util/performance-util.js +3 -4
- package/package.json +2 -3
- package/lib/object-util/cloneDeep/performanceTest.d.ts +0 -1
- package/lib/object-util/cloneDeep/performanceTest.js +0 -106
|
@@ -87,7 +87,7 @@ function demonstrateParentNodeId() {
|
|
|
87
87
|
console.log('Example 5: Concurrent async operations with explicit parent');
|
|
88
88
|
yield (0, performance_util_1.withTimingAsync)('Main Operation', () => __awaiter(this, void 0, void 0, function* () {
|
|
89
89
|
const mainOpId = (0, performance_util_1.getCurrentParentNodeId)();
|
|
90
|
-
console.log(`Main Operation ID: ${mainOpId}`);
|
|
90
|
+
console.log(`Main Operation ID: ${String(mainOpId)}`);
|
|
91
91
|
console.log('Starting concurrent operations...');
|
|
92
92
|
const results = yield Promise.all([
|
|
93
93
|
(0, performance_util_1.withTimingAsync)('Fetch User Data', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -173,7 +173,7 @@ function demonstrateSyncWithParentId() {
|
|
|
173
173
|
console.log('Example 7: Sync functions with explicit parent');
|
|
174
174
|
(0, performance_util_1.withTimingSync)('Data Processing Pipeline', () => {
|
|
175
175
|
const pipelineId = (0, performance_util_1.getCurrentParentNodeId)();
|
|
176
|
-
console.log(`Pipeline ID: ${pipelineId}`);
|
|
176
|
+
console.log(`Pipeline ID: ${String(pipelineId)}`);
|
|
177
177
|
(0, performance_util_1.withTimingSync)('Load Input Data', () => {
|
|
178
178
|
const start = performance.now();
|
|
179
179
|
while (performance.now() < start + 50) {
|
|
@@ -213,7 +213,7 @@ function demonstrateManualSpansWithParentId() {
|
|
|
213
213
|
console.log('Example 8: Manual spans with explicit parent');
|
|
214
214
|
(0, performance_util_1.startSpan)('Service Request');
|
|
215
215
|
const serviceId = (0, performance_util_1.getCurrentParentNodeId)();
|
|
216
|
-
console.log(`Service Request ID: ${serviceId}`);
|
|
216
|
+
console.log(`Service Request ID: ${String(serviceId)}`);
|
|
217
217
|
(0, performance_util_1.startSpan)('Authenticate User');
|
|
218
218
|
const start1 = performance.now();
|
|
219
219
|
while (performance.now() < start1 + 30) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
type TimingSpans = TimingNode[];
|
|
2
2
|
type TimingStack = TimingNode[];
|
|
3
|
-
type TimingNode = {
|
|
3
|
+
export type TimingNode = {
|
|
4
4
|
label: string;
|
|
5
|
-
id:
|
|
5
|
+
id: symbol;
|
|
6
6
|
durationMs: number;
|
|
7
7
|
children: TimingNode[];
|
|
8
8
|
startTime: number;
|
|
@@ -14,22 +14,22 @@ type ActiveSpan = {
|
|
|
14
14
|
};
|
|
15
15
|
type TimingProfile = {
|
|
16
16
|
activeSpans: Map<string, ActiveSpan>;
|
|
17
|
-
spansById: Map<
|
|
17
|
+
spansById: Map<symbol, TimingNode>;
|
|
18
18
|
timingSpans: TimingSpans;
|
|
19
19
|
timingStack: TimingStack;
|
|
20
20
|
};
|
|
21
21
|
export declare function getDefaultTimingProfile(): TimingProfile;
|
|
22
22
|
export declare function clearDefaultTimingProfile(): void;
|
|
23
|
-
export declare function getCurrentParentNodeId():
|
|
23
|
+
export declare function getCurrentParentNodeId(): symbol | null;
|
|
24
24
|
export declare function withTimingAsync<T>(label: string, fn: () => Promise<T>, options?: {
|
|
25
|
-
parentNodeId?:
|
|
25
|
+
parentNodeId?: symbol | null;
|
|
26
26
|
}): Promise<T>;
|
|
27
27
|
export declare function withTimingSync<T>(label: string, fn: () => T, options?: {
|
|
28
|
-
parentNodeId?:
|
|
28
|
+
parentNodeId?: symbol | null;
|
|
29
29
|
}): T;
|
|
30
30
|
export declare function displayTimingTree(nodes?: TimingSpans, depth?: number): string;
|
|
31
31
|
export declare function startSpan(spanName: string, options?: {
|
|
32
|
-
parentNodeId?:
|
|
32
|
+
parentNodeId?: symbol | null;
|
|
33
33
|
}): void;
|
|
34
34
|
export declare function endSpan(spanName: string): void;
|
|
35
35
|
export {};
|
|
@@ -17,7 +17,6 @@ exports.withTimingSync = withTimingSync;
|
|
|
17
17
|
exports.displayTimingTree = displayTimingTree;
|
|
18
18
|
exports.startSpan = startSpan;
|
|
19
19
|
exports.endSpan = endSpan;
|
|
20
|
-
const nanoid_1 = require("nanoid");
|
|
21
20
|
const DEFAULT_TIMING_PROFILE = {
|
|
22
21
|
activeSpans: new Map(),
|
|
23
22
|
spansById: new Map(),
|
|
@@ -57,7 +56,7 @@ function withTimingAsync(label, fn, options) {
|
|
|
57
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
57
|
const start = performance.now();
|
|
59
58
|
const chosenId = options === null || options === void 0 ? void 0 : options.parentNodeId;
|
|
60
|
-
const uniqueId = (
|
|
59
|
+
const uniqueId = Symbol();
|
|
61
60
|
const timingNode = {
|
|
62
61
|
label,
|
|
63
62
|
durationMs: 0,
|
|
@@ -89,7 +88,7 @@ function withTimingAsync(label, fn, options) {
|
|
|
89
88
|
function withTimingSync(label, fn, options) {
|
|
90
89
|
const start = performance.now();
|
|
91
90
|
const chosenId = options === null || options === void 0 ? void 0 : options.parentNodeId;
|
|
92
|
-
const uniqueId = (
|
|
91
|
+
const uniqueId = Symbol();
|
|
93
92
|
const timingNode = {
|
|
94
93
|
label,
|
|
95
94
|
durationMs: 0,
|
|
@@ -194,7 +193,7 @@ function startSpan(spanName, options) {
|
|
|
194
193
|
}
|
|
195
194
|
const startTime = performance.now();
|
|
196
195
|
const chosenId = options === null || options === void 0 ? void 0 : options.parentNodeId;
|
|
197
|
-
const uniqueId = (
|
|
196
|
+
const uniqueId = Symbol();
|
|
198
197
|
const timingNode = {
|
|
199
198
|
label: spanName,
|
|
200
199
|
durationMs: 0,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/util",
|
|
3
|
-
"version": "1.1.15-alpha-
|
|
3
|
+
"version": "1.1.15-alpha-11",
|
|
4
4
|
"description": "General JavaScript utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@contrail/types": "^3.0.95",
|
|
43
43
|
"fflate": "^0.8.2",
|
|
44
|
-
"lodash": "^4.17.21"
|
|
45
|
-
"nanoid": "^5.1.5"
|
|
44
|
+
"lodash": "^4.17.21"
|
|
46
45
|
}
|
|
47
46
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const lodash_1 = require("lodash");
|
|
4
|
-
const cloneDeep_1 = require("./cloneDeep");
|
|
5
|
-
function jsonClone(obj) {
|
|
6
|
-
return JSON.parse(JSON.stringify(obj));
|
|
7
|
-
}
|
|
8
|
-
console.log('Performance test for small objects:');
|
|
9
|
-
let smallObject = {
|
|
10
|
-
sub1: {
|
|
11
|
-
val: 1,
|
|
12
|
-
},
|
|
13
|
-
sub3: {
|
|
14
|
-
val: 2,
|
|
15
|
-
valX: '3',
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
console.time('cloneDeepSmallRFDC');
|
|
19
|
-
Array.from({ length: 10000 }).forEach(() => {
|
|
20
|
-
(0, cloneDeep_1.cloneDeep)(smallObject);
|
|
21
|
-
});
|
|
22
|
-
console.timeEnd('cloneDeepSmallRFDC');
|
|
23
|
-
console.time('cloneDeepSmallLodash');
|
|
24
|
-
Array.from({ length: 10000 }).forEach(() => {
|
|
25
|
-
(0, lodash_1.cloneDeep)(smallObject);
|
|
26
|
-
});
|
|
27
|
-
console.timeEnd('cloneDeepSmallLodash');
|
|
28
|
-
console.time('cloneDeepSmallJson');
|
|
29
|
-
Array.from({ length: 10000 }).forEach(() => {
|
|
30
|
-
jsonClone(smallObject);
|
|
31
|
-
});
|
|
32
|
-
console.timeEnd('cloneDeepSmallJson');
|
|
33
|
-
console.time('structuredCloneSmall');
|
|
34
|
-
Array.from({ length: 10000 }).forEach(() => {
|
|
35
|
-
structuredClone(smallObject);
|
|
36
|
-
});
|
|
37
|
-
console.timeEnd('structuredCloneSmall');
|
|
38
|
-
console.log('\n\nPerformance test for very large objects:');
|
|
39
|
-
let veryLargeObject = {};
|
|
40
|
-
for (let i = 0; i < 100000; i++) {
|
|
41
|
-
veryLargeObject[`key${i}`] = {
|
|
42
|
-
sub1: {
|
|
43
|
-
val: i,
|
|
44
|
-
},
|
|
45
|
-
sub2: new Date('2023-10-01T12:00:00.000Z'),
|
|
46
|
-
sub3: {
|
|
47
|
-
val: i + 1,
|
|
48
|
-
valX: i + 2,
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
console.time('cloneDeepRFDC');
|
|
53
|
-
(0, cloneDeep_1.cloneDeep)(veryLargeObject);
|
|
54
|
-
console.timeEnd('cloneDeepRFDC');
|
|
55
|
-
console.time('cloneDeepLodash');
|
|
56
|
-
(0, lodash_1.cloneDeep)(veryLargeObject);
|
|
57
|
-
console.timeEnd('cloneDeepLodash');
|
|
58
|
-
console.time('cloneDeepJson');
|
|
59
|
-
jsonClone(veryLargeObject);
|
|
60
|
-
console.timeEnd('cloneDeepJson');
|
|
61
|
-
console.time('structuredClone');
|
|
62
|
-
structuredClone(veryLargeObject);
|
|
63
|
-
console.timeEnd('structuredClone');
|
|
64
|
-
console.log('\n\nPerformance test for very large arrays:');
|
|
65
|
-
let veryLargeArray = [];
|
|
66
|
-
for (let i = 0; i < 100000; i++) {
|
|
67
|
-
veryLargeArray.push({
|
|
68
|
-
sub1: {
|
|
69
|
-
val: i,
|
|
70
|
-
},
|
|
71
|
-
sub2: new Date('2023-10-01T12:00:00.000Z'),
|
|
72
|
-
sub3: {
|
|
73
|
-
val: i + 1,
|
|
74
|
-
valX: i + 2,
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
console.time('cloneDeepArrayRFDC');
|
|
79
|
-
(0, cloneDeep_1.cloneDeep)(veryLargeArray);
|
|
80
|
-
console.timeEnd('cloneDeepArrayRFDC');
|
|
81
|
-
console.time('cloneDeepArrayLodash');
|
|
82
|
-
(0, lodash_1.cloneDeep)(veryLargeArray);
|
|
83
|
-
console.timeEnd('cloneDeepArrayLodash');
|
|
84
|
-
console.time('cloneDeepArrayJson');
|
|
85
|
-
jsonClone(veryLargeArray);
|
|
86
|
-
console.timeEnd('cloneDeepArrayJson');
|
|
87
|
-
console.time('structuredCloneArray');
|
|
88
|
-
structuredClone(veryLargeArray);
|
|
89
|
-
console.timeEnd('structuredCloneArray');
|
|
90
|
-
console.log('\n\nPerformance test for assortment.json:');
|
|
91
|
-
const fs = require("fs");
|
|
92
|
-
const path = require("path");
|
|
93
|
-
const assortmentFilePath = path.join(__dirname, 'assortment.json');
|
|
94
|
-
const assortmentData = JSON.parse(fs.readFileSync(assortmentFilePath, 'utf8'));
|
|
95
|
-
console.time('cloneDeepAssortment25kRFDC');
|
|
96
|
-
(0, cloneDeep_1.cloneDeep)(assortmentData);
|
|
97
|
-
console.timeEnd('cloneDeepAssortment25kRFDC');
|
|
98
|
-
console.time('cloneDeepAssortment25kLodash');
|
|
99
|
-
(0, lodash_1.cloneDeep)(assortmentData);
|
|
100
|
-
console.timeEnd('cloneDeepAssortment25kLodash');
|
|
101
|
-
console.time('cloneDeepAssortment25kJson');
|
|
102
|
-
jsonClone(assortmentData);
|
|
103
|
-
console.timeEnd('cloneDeepAssortment25kJson');
|
|
104
|
-
console.time('structuredCloneAssortment25k');
|
|
105
|
-
structuredClone(assortmentData);
|
|
106
|
-
console.timeEnd('structuredCloneAssortment25k');
|