@gnsx/three 0.186.0 → 0.186.3
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/build/three.core.js +79 -6
- package/examples/jsm/inspector/Inspector.js +60 -1
- package/examples/jsm/inspector/tabs/Memory.js +60 -1
- package/examples/jsm/inspector/ui/Profiler.js +6 -0
- package/examples/jsm/inspector/ui/Style.js +53 -1
- package/examples/jsm/inspector/ui/utils.js +121 -0
- package/package.json +1 -1
- package/src/utils.js +79 -6
package/build/three.core.js
CHANGED
|
@@ -2087,9 +2087,79 @@ function warnOnce( ...params ) {
|
|
|
2087
2087
|
|
|
2088
2088
|
}
|
|
2089
2089
|
|
|
2090
|
+
// WITH_GENESYS
|
|
2091
|
+
/**
|
|
2092
|
+
* Shared MessageChannel used by {@link yieldToTask}. One pair of ports is
|
|
2093
|
+
* owned for the lifetime of this module so compileAsync does not allocate a
|
|
2094
|
+
* channel per yield.
|
|
2095
|
+
*
|
|
2096
|
+
* @private
|
|
2097
|
+
* @type {MessageChannel|null}
|
|
2098
|
+
*/
|
|
2099
|
+
let _taskYieldChannel = null;
|
|
2100
|
+
|
|
2101
|
+
/**
|
|
2102
|
+
* Resolvers waiting for the next MessageChannel task. Sequential
|
|
2103
|
+
* `await yieldToMain()` callers queue at most one entry; the array still
|
|
2104
|
+
* preserves ordering if several yields overlap.
|
|
2105
|
+
*
|
|
2106
|
+
* @private
|
|
2107
|
+
* @type {Array<Function>}
|
|
2108
|
+
*/
|
|
2109
|
+
const _taskYieldResolvers = [];
|
|
2110
|
+
|
|
2111
|
+
/**
|
|
2112
|
+
* Yields to a new event-loop task without waiting for a display frame.
|
|
2113
|
+
*
|
|
2114
|
+
* @private
|
|
2115
|
+
* @return {Promise<void>}
|
|
2116
|
+
*/
|
|
2117
|
+
function yieldToTask() {
|
|
2118
|
+
|
|
2119
|
+
return new Promise( resolve => {
|
|
2120
|
+
|
|
2121
|
+
if ( typeof MessageChannel === 'function' ) {
|
|
2122
|
+
|
|
2123
|
+
if ( _taskYieldChannel === null ) {
|
|
2124
|
+
|
|
2125
|
+
_taskYieldChannel = new MessageChannel();
|
|
2126
|
+
_taskYieldChannel.port1.onmessage = function () {
|
|
2127
|
+
|
|
2128
|
+
const next = _taskYieldResolvers.shift();
|
|
2129
|
+
if ( next !== undefined ) next();
|
|
2130
|
+
|
|
2131
|
+
};
|
|
2132
|
+
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
_taskYieldResolvers.push( resolve );
|
|
2136
|
+
_taskYieldChannel.port2.postMessage( null );
|
|
2137
|
+
return;
|
|
2138
|
+
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
if ( typeof setTimeout === 'function' ) {
|
|
2142
|
+
|
|
2143
|
+
setTimeout( resolve, 0 );
|
|
2144
|
+
return;
|
|
2145
|
+
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
resolve();
|
|
2149
|
+
|
|
2150
|
+
} );
|
|
2151
|
+
|
|
2152
|
+
}
|
|
2153
|
+
// !WITH_GENESYS
|
|
2154
|
+
|
|
2090
2155
|
/**
|
|
2091
2156
|
* Yields execution to the main thread to allow rendering and other tasks.
|
|
2092
|
-
* Uses scheduler.yield() when available (Chrome 115+)
|
|
2157
|
+
* Uses scheduler.yield() when available (Chrome 115+).
|
|
2158
|
+
* WITH_GENESYS
|
|
2159
|
+
* Falls back to a MessageChannel (or setTimeout) task continuation so browsers
|
|
2160
|
+
* without the Scheduler API do not wait one animation frame per yield.
|
|
2161
|
+
* !WITH_GENESYS
|
|
2162
|
+
* Falls back to requestAnimationFrame.
|
|
2093
2163
|
*
|
|
2094
2164
|
* @return {Promise<void>}
|
|
2095
2165
|
*/
|
|
@@ -2101,11 +2171,14 @@ function yieldToMain() {
|
|
|
2101
2171
|
|
|
2102
2172
|
}
|
|
2103
2173
|
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2174
|
+
// WITH_GENESYS
|
|
2175
|
+
return yieldToTask();
|
|
2176
|
+
// !WITH_GENESYS
|
|
2177
|
+
// return new Promise( resolve => {
|
|
2178
|
+
//
|
|
2179
|
+
// requestAnimationFrame( resolve );
|
|
2180
|
+
//
|
|
2181
|
+
// } );
|
|
2109
2182
|
|
|
2110
2183
|
}
|
|
2111
2184
|
|
|
@@ -8,7 +8,14 @@ import { Parameters } from './tabs/Parameters.js';
|
|
|
8
8
|
import { Settings } from './tabs/Settings.js';
|
|
9
9
|
import { Viewer } from './tabs/Viewer.js';
|
|
10
10
|
import { Timeline } from './tabs/Timeline.js';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
setText,
|
|
13
|
+
// WITH_GENESYS
|
|
14
|
+
getJSHeapBytes,
|
|
15
|
+
startJSHeapSampling,
|
|
16
|
+
stopJSHeapSampling
|
|
17
|
+
// !WITH_GENESYS
|
|
18
|
+
} from './ui/utils.js';
|
|
12
19
|
|
|
13
20
|
import { setConsoleFunction, getConsoleFunction, REVISION } from '@gnsx/three/webgpu';
|
|
14
21
|
|
|
@@ -24,6 +31,10 @@ class Inspector extends RendererInspector {
|
|
|
24
31
|
|
|
25
32
|
this.nonce = nonce;
|
|
26
33
|
|
|
34
|
+
// WITH_GENESYS
|
|
35
|
+
startJSHeapSampling();
|
|
36
|
+
// !WITH_GENESYS
|
|
37
|
+
|
|
27
38
|
// init profiler
|
|
28
39
|
|
|
29
40
|
const profiler = new Profiler( this, options );
|
|
@@ -589,6 +600,50 @@ class Inspector extends RendererInspector {
|
|
|
589
600
|
|
|
590
601
|
setText( this.profiler.toggleButton.querySelector( '.fps-counter' ), this.fps.toFixed() );
|
|
591
602
|
|
|
603
|
+
// WITH_GENESYS
|
|
604
|
+
const toggle = this.profiler.toggleButton;
|
|
605
|
+
const gpuCounter = toggle.querySelector( '.gpu-counter' );
|
|
606
|
+
const gpuLabel = toggle.querySelector( '.gpu-label' );
|
|
607
|
+
const heapCounter = toggle.querySelector( '.heap-counter' );
|
|
608
|
+
const heapLabel = toggle.querySelector( '.heap-label' );
|
|
609
|
+
const gpuBytes = this.getRenderer()?.info?.memory?.total;
|
|
610
|
+
const heap = getJSHeapBytes();
|
|
611
|
+
|
|
612
|
+
if ( gpuCounter ) {
|
|
613
|
+
|
|
614
|
+
if ( typeof gpuBytes === 'number' ) {
|
|
615
|
+
|
|
616
|
+
setText( gpuCounter, ( gpuBytes / ( 1024 * 1024 ) ).toFixed( 0 ) );
|
|
617
|
+
gpuCounter.style.display = '';
|
|
618
|
+
if ( gpuLabel ) gpuLabel.style.display = '';
|
|
619
|
+
|
|
620
|
+
} else {
|
|
621
|
+
|
|
622
|
+
gpuCounter.style.display = 'none';
|
|
623
|
+
if ( gpuLabel ) gpuLabel.style.display = 'none';
|
|
624
|
+
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
if ( heapCounter ) {
|
|
630
|
+
|
|
631
|
+
if ( heap ) {
|
|
632
|
+
|
|
633
|
+
setText( heapCounter, ( heap.used / ( 1024 * 1024 ) ).toFixed( 0 ) );
|
|
634
|
+
heapCounter.style.display = '';
|
|
635
|
+
if ( heapLabel ) heapLabel.style.display = '';
|
|
636
|
+
|
|
637
|
+
} else {
|
|
638
|
+
|
|
639
|
+
heapCounter.style.display = 'none';
|
|
640
|
+
if ( heapLabel ) heapLabel.style.display = 'none';
|
|
641
|
+
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
}
|
|
645
|
+
// !WITH_GENESYS
|
|
646
|
+
|
|
592
647
|
this.performance.updateText( this, frame );
|
|
593
648
|
this.memory.updateText( this );
|
|
594
649
|
|
|
@@ -633,6 +688,10 @@ class Inspector extends RendererInspector {
|
|
|
633
688
|
|
|
634
689
|
dispose() {
|
|
635
690
|
|
|
691
|
+
// WITH_GENESYS
|
|
692
|
+
stopJSHeapSampling();
|
|
693
|
+
// !WITH_GENESYS
|
|
694
|
+
|
|
636
695
|
super.dispose();
|
|
637
696
|
|
|
638
697
|
this.setRenderer( null );
|
|
@@ -2,7 +2,15 @@ import { Tab } from '../ui/Tab.js';
|
|
|
2
2
|
import { List } from '../ui/List.js';
|
|
3
3
|
import { Graph } from '../ui/Graph.js';
|
|
4
4
|
import { Item } from '../ui/Item.js';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
createValueSpan,
|
|
7
|
+
setText,
|
|
8
|
+
formatBytes,
|
|
9
|
+
info,
|
|
10
|
+
// WITH_GENESYS
|
|
11
|
+
getJSHeapBytes
|
|
12
|
+
// !WITH_GENESYS
|
|
13
|
+
} from '../ui/utils.js';
|
|
6
14
|
|
|
7
15
|
class Memory extends Tab {
|
|
8
16
|
|
|
@@ -26,6 +34,9 @@ class Memory extends Tab {
|
|
|
26
34
|
|
|
27
35
|
const graph = new Graph();
|
|
28
36
|
graph.addLine( 'total', 'var( --color-yellow )' );
|
|
37
|
+
// WITH_GENESYS
|
|
38
|
+
graph.addLine( 'jsHeap', 'var( --color-accent )' );
|
|
39
|
+
// !WITH_GENESYS
|
|
29
40
|
graphContainer.append( graph.domElement );
|
|
30
41
|
|
|
31
42
|
// stats
|
|
@@ -37,6 +48,13 @@ class Memory extends Tab {
|
|
|
37
48
|
graphItem.itemRow.childNodes[ 0 ].style.gridColumn = '1 / -1';
|
|
38
49
|
graphStats.add( graphItem );
|
|
39
50
|
|
|
51
|
+
// WITH_GENESYS
|
|
52
|
+
const legend = document.createElement( 'div' );
|
|
53
|
+
legend.className = 'graph-caption graph-legend';
|
|
54
|
+
legend.innerHTML = '<span class="graph-legend-item graph-legend-gpu">GPU</span><span class="graph-legend-item graph-legend-heap">JS Heap</span>';
|
|
55
|
+
graphContainer.prepend( legend );
|
|
56
|
+
// !WITH_GENESYS
|
|
57
|
+
|
|
40
58
|
// info
|
|
41
59
|
|
|
42
60
|
this.memoryStats = new Item( 'Renderer Info', '', createValueSpan() );
|
|
@@ -73,6 +91,19 @@ class Memory extends Tab {
|
|
|
73
91
|
this.uniformBuffers = new Item( 'Uniform Buffers', createValueSpan(), createValueSpan() );
|
|
74
92
|
this.memoryStats.add( this.uniformBuffers );
|
|
75
93
|
|
|
94
|
+
// WITH_GENESYS
|
|
95
|
+
this.jsHeapStats = new Item( 'JS Heap', '', createValueSpan() );
|
|
96
|
+
this.jsHeapStats.domElement.firstChild.classList.add( 'no-hover' );
|
|
97
|
+
memoryList.add( this.jsHeapStats );
|
|
98
|
+
info( this.jsHeapStats.domElement.querySelector( '.list-item-cell' ), 'Chromium reports V8 heap via performance.memory (used / allocated / limit). Other browsers only report a page-memory estimate if performance.measureUserAgentSpecificMemory is available in a cross-origin isolated document. Safari and Firefox do not expose JS heap size to web pages.' );
|
|
99
|
+
|
|
100
|
+
this.jsHeapAllocated = new Item( 'Allocated', '', createValueSpan() );
|
|
101
|
+
this.jsHeapStats.add( this.jsHeapAllocated );
|
|
102
|
+
|
|
103
|
+
this.jsHeapLimit = new Item( 'Limit', '', createValueSpan() );
|
|
104
|
+
this.jsHeapStats.add( this.jsHeapLimit );
|
|
105
|
+
// !WITH_GENESYS
|
|
106
|
+
|
|
76
107
|
this.graph = graph;
|
|
77
108
|
|
|
78
109
|
}
|
|
@@ -85,6 +116,16 @@ class Memory extends Tab {
|
|
|
85
116
|
|
|
86
117
|
this.graph.addPoint( 'total', memory.total );
|
|
87
118
|
|
|
119
|
+
// WITH_GENESYS
|
|
120
|
+
const heap = getJSHeapBytes();
|
|
121
|
+
|
|
122
|
+
if ( heap ) {
|
|
123
|
+
|
|
124
|
+
this.graph.addPoint( 'jsHeap', heap.used );
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
// !WITH_GENESYS
|
|
128
|
+
|
|
88
129
|
if ( this.graph.limit === 0 ) this.graph.limit = 1;
|
|
89
130
|
|
|
90
131
|
this.graph.update();
|
|
@@ -127,6 +168,24 @@ class Memory extends Tab {
|
|
|
127
168
|
setText( this.uniformBuffers.data[ 1 ], memory.uniformBuffers.toString() );
|
|
128
169
|
setText( this.uniformBuffers.data[ 2 ], formatBytes( memory.uniformBuffersSize ) );
|
|
129
170
|
|
|
171
|
+
// WITH_GENESYS
|
|
172
|
+
const heap = getJSHeapBytes();
|
|
173
|
+
|
|
174
|
+
if ( heap ) {
|
|
175
|
+
|
|
176
|
+
setText( this.jsHeapStats.data[ 2 ], formatBytes( heap.used ) );
|
|
177
|
+
setText( this.jsHeapAllocated.data[ 2 ], heap.total !== undefined ? formatBytes( heap.total ) : 'N/A' );
|
|
178
|
+
setText( this.jsHeapLimit.data[ 2 ], heap.limit !== undefined ? formatBytes( heap.limit ) : 'N/A' );
|
|
179
|
+
|
|
180
|
+
} else {
|
|
181
|
+
|
|
182
|
+
setText( this.jsHeapStats.data[ 2 ], 'Unsupported' );
|
|
183
|
+
setText( this.jsHeapAllocated.data[ 2 ], 'N/A' );
|
|
184
|
+
setText( this.jsHeapLimit.data[ 2 ], 'N/A' );
|
|
185
|
+
|
|
186
|
+
}
|
|
187
|
+
// !WITH_GENESYS
|
|
188
|
+
|
|
130
189
|
}
|
|
131
190
|
|
|
132
191
|
}
|
|
@@ -271,6 +271,12 @@ export class Profiler extends EventDispatcher {
|
|
|
271
271
|
<span class="toggle-text">
|
|
272
272
|
<span class="fps-counter">-</span>
|
|
273
273
|
<span class="fps-label">FPS</span>
|
|
274
|
+
<!-- WITH_GENESYS -->
|
|
275
|
+
<span class="gpu-counter" title="GPU memory (MB)">-</span>
|
|
276
|
+
<span class="gpu-label">GPU</span>
|
|
277
|
+
<span class="heap-counter" title="JS heap used (MB)">-</span>
|
|
278
|
+
<span class="heap-label">JS</span>
|
|
279
|
+
<!-- !WITH_GENESYS -->
|
|
274
280
|
</span>
|
|
275
281
|
<span class="toggle-icon">
|
|
276
282
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-device-ipad-horizontal-search"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M11.5 20h-6.5a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v5.5" /><path d="M9 17h2" /><path d="M18 18m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0" /><path d="M20.2 20.2l1.8 1.8" /></svg>
|
|
@@ -179,7 +179,10 @@ export class Style {
|
|
|
179
179
|
display: flex;
|
|
180
180
|
align-items: baseline;
|
|
181
181
|
padding: 8px 14px;
|
|
182
|
-
|
|
182
|
+
/* WITH_GENESYS */
|
|
183
|
+
min-width: 196px;
|
|
184
|
+
/* !WITH_GENESYS */
|
|
185
|
+
/* min-width: 80px; */
|
|
183
186
|
justify-content: right;
|
|
184
187
|
}
|
|
185
188
|
|
|
@@ -189,6 +192,20 @@ export class Style {
|
|
|
189
192
|
color: #999;
|
|
190
193
|
}
|
|
191
194
|
|
|
195
|
+
/* WITH_GENESYS */
|
|
196
|
+
.toggle-text .gpu-counter,
|
|
197
|
+
.toggle-text .heap-counter {
|
|
198
|
+
margin-left: 12px;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.toggle-text .gpu-label,
|
|
202
|
+
.toggle-text .heap-label {
|
|
203
|
+
font-size: 0.7em;
|
|
204
|
+
margin-left: 6px;
|
|
205
|
+
color: #999;
|
|
206
|
+
}
|
|
207
|
+
/* !WITH_GENESYS */
|
|
208
|
+
|
|
192
209
|
.builtin-tabs-container {
|
|
193
210
|
position: relative;
|
|
194
211
|
z-index: 1;
|
|
@@ -1251,6 +1268,41 @@ export class Style {
|
|
|
1251
1268
|
position: relative;
|
|
1252
1269
|
}
|
|
1253
1270
|
|
|
1271
|
+
/* WITH_GENESYS */
|
|
1272
|
+
.graph-caption {
|
|
1273
|
+
font-size: 11px;
|
|
1274
|
+
color: var(--text-secondary);
|
|
1275
|
+
margin-bottom: 4px;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
.graph-legend {
|
|
1279
|
+
display: flex;
|
|
1280
|
+
gap: 12px;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
.graph-legend-item {
|
|
1284
|
+
display: inline-flex;
|
|
1285
|
+
align-items: center;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
.graph-legend-item::before {
|
|
1289
|
+
content: '';
|
|
1290
|
+
display: inline-block;
|
|
1291
|
+
width: 8px;
|
|
1292
|
+
height: 8px;
|
|
1293
|
+
border-radius: 2px;
|
|
1294
|
+
margin-right: 6px;
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
.graph-legend-gpu::before {
|
|
1298
|
+
background: var(--color-yellow);
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
.graph-legend-heap::before {
|
|
1302
|
+
background: var(--color-accent);
|
|
1303
|
+
}
|
|
1304
|
+
/* !WITH_GENESYS */
|
|
1305
|
+
|
|
1254
1306
|
.graph-svg, .graph-canvas {
|
|
1255
1307
|
width: 0;
|
|
1256
1308
|
min-width: 100%;
|
|
@@ -62,6 +62,127 @@ export function formatBytes( bytes, decimals = 2 ) {
|
|
|
62
62
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
// WITH_GENESYS
|
|
66
|
+
/**
|
|
67
|
+
* Best-effort JS / page memory sample for the inspector.
|
|
68
|
+
*
|
|
69
|
+
* Chromium exposes a sync V8 heap via `performance.memory`. The spec method
|
|
70
|
+
* `performance.measureUserAgentSpecificMemory()` is async, may include more
|
|
71
|
+
* than JS heap, and requires a cross-origin isolated document. Firefox and
|
|
72
|
+
* Safari do not expose JS heap size to web content as of 2026.
|
|
73
|
+
*
|
|
74
|
+
* @returns {{ used: number, total?: number, limit?: number } | null}
|
|
75
|
+
*/
|
|
76
|
+
let _specMemoryBytes = null;
|
|
77
|
+
let _specMemoryTimer = 0;
|
|
78
|
+
let _specMemorySampling = false;
|
|
79
|
+
|
|
80
|
+
function readPerformanceMemory() {
|
|
81
|
+
|
|
82
|
+
const memory = performance.memory;
|
|
83
|
+
|
|
84
|
+
if ( memory === undefined || typeof memory.usedJSHeapSize !== 'number' ) {
|
|
85
|
+
|
|
86
|
+
return null;
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
used: memory.usedJSHeapSize,
|
|
92
|
+
total: memory.totalJSHeapSize,
|
|
93
|
+
limit: memory.jsHeapSizeLimit
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function sampleSpecMemory() {
|
|
99
|
+
|
|
100
|
+
const measure = performance.measureUserAgentSpecificMemory;
|
|
101
|
+
|
|
102
|
+
if ( typeof measure !== 'function' ) {
|
|
103
|
+
|
|
104
|
+
return;
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
|
|
110
|
+
const result = await measure.call( performance );
|
|
111
|
+
|
|
112
|
+
if ( result && typeof result.bytes === 'number' ) {
|
|
113
|
+
|
|
114
|
+
_specMemoryBytes = result.bytes;
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
} catch {
|
|
119
|
+
|
|
120
|
+
// SecurityError when the document is not cross-origin isolated.
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function scheduleSpecMemorySample() {
|
|
127
|
+
|
|
128
|
+
if ( _specMemorySampling === false ) {
|
|
129
|
+
|
|
130
|
+
return;
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Spec guidance: poll on a randomized interval; the call may wait on GC.
|
|
135
|
+
_specMemoryTimer = setTimeout( () => {
|
|
136
|
+
|
|
137
|
+
sampleSpecMemory().finally( scheduleSpecMemorySample );
|
|
138
|
+
|
|
139
|
+
}, 8000 + Math.random() * 7000 );
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function startJSHeapSampling() {
|
|
144
|
+
|
|
145
|
+
if ( _specMemorySampling ) {
|
|
146
|
+
|
|
147
|
+
return;
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
_specMemorySampling = true;
|
|
152
|
+
sampleSpecMemory();
|
|
153
|
+
scheduleSpecMemorySample();
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function stopJSHeapSampling() {
|
|
158
|
+
|
|
159
|
+
_specMemorySampling = false;
|
|
160
|
+
clearTimeout( _specMemoryTimer );
|
|
161
|
+
_specMemoryTimer = 0;
|
|
162
|
+
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function getJSHeapBytes() {
|
|
166
|
+
|
|
167
|
+
const chromeHeap = readPerformanceMemory();
|
|
168
|
+
|
|
169
|
+
if ( chromeHeap ) {
|
|
170
|
+
|
|
171
|
+
return chromeHeap;
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if ( typeof _specMemoryBytes === 'number' ) {
|
|
176
|
+
|
|
177
|
+
return { used: _specMemoryBytes };
|
|
178
|
+
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return null;
|
|
182
|
+
|
|
183
|
+
}
|
|
184
|
+
// !WITH_GENESYS
|
|
185
|
+
|
|
65
186
|
export function info( parentNode, text ) {
|
|
66
187
|
|
|
67
188
|
let infoIcon = parentNode.querySelector( '.info-icon' );
|
package/package.json
CHANGED
package/src/utils.js
CHANGED
|
@@ -347,9 +347,79 @@ function warnOnce( ...params ) {
|
|
|
347
347
|
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
+
// WITH_GENESYS
|
|
351
|
+
/**
|
|
352
|
+
* Shared MessageChannel used by {@link yieldToTask}. One pair of ports is
|
|
353
|
+
* owned for the lifetime of this module so compileAsync does not allocate a
|
|
354
|
+
* channel per yield.
|
|
355
|
+
*
|
|
356
|
+
* @private
|
|
357
|
+
* @type {MessageChannel|null}
|
|
358
|
+
*/
|
|
359
|
+
let _taskYieldChannel = null;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Resolvers waiting for the next MessageChannel task. Sequential
|
|
363
|
+
* `await yieldToMain()` callers queue at most one entry; the array still
|
|
364
|
+
* preserves ordering if several yields overlap.
|
|
365
|
+
*
|
|
366
|
+
* @private
|
|
367
|
+
* @type {Array<Function>}
|
|
368
|
+
*/
|
|
369
|
+
const _taskYieldResolvers = [];
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Yields to a new event-loop task without waiting for a display frame.
|
|
373
|
+
*
|
|
374
|
+
* @private
|
|
375
|
+
* @return {Promise<void>}
|
|
376
|
+
*/
|
|
377
|
+
function yieldToTask() {
|
|
378
|
+
|
|
379
|
+
return new Promise( resolve => {
|
|
380
|
+
|
|
381
|
+
if ( typeof MessageChannel === 'function' ) {
|
|
382
|
+
|
|
383
|
+
if ( _taskYieldChannel === null ) {
|
|
384
|
+
|
|
385
|
+
_taskYieldChannel = new MessageChannel();
|
|
386
|
+
_taskYieldChannel.port1.onmessage = function () {
|
|
387
|
+
|
|
388
|
+
const next = _taskYieldResolvers.shift();
|
|
389
|
+
if ( next !== undefined ) next();
|
|
390
|
+
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
_taskYieldResolvers.push( resolve );
|
|
396
|
+
_taskYieldChannel.port2.postMessage( null );
|
|
397
|
+
return;
|
|
398
|
+
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if ( typeof setTimeout === 'function' ) {
|
|
402
|
+
|
|
403
|
+
setTimeout( resolve, 0 );
|
|
404
|
+
return;
|
|
405
|
+
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
resolve();
|
|
409
|
+
|
|
410
|
+
} );
|
|
411
|
+
|
|
412
|
+
}
|
|
413
|
+
// !WITH_GENESYS
|
|
414
|
+
|
|
350
415
|
/**
|
|
351
416
|
* Yields execution to the main thread to allow rendering and other tasks.
|
|
352
|
-
* Uses scheduler.yield() when available (Chrome 115+)
|
|
417
|
+
* Uses scheduler.yield() when available (Chrome 115+).
|
|
418
|
+
* WITH_GENESYS
|
|
419
|
+
* Falls back to a MessageChannel (or setTimeout) task continuation so browsers
|
|
420
|
+
* without the Scheduler API do not wait one animation frame per yield.
|
|
421
|
+
* !WITH_GENESYS
|
|
422
|
+
* Falls back to requestAnimationFrame.
|
|
353
423
|
*
|
|
354
424
|
* @return {Promise<void>}
|
|
355
425
|
*/
|
|
@@ -361,11 +431,14 @@ function yieldToMain() {
|
|
|
361
431
|
|
|
362
432
|
}
|
|
363
433
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
434
|
+
// WITH_GENESYS
|
|
435
|
+
return yieldToTask();
|
|
436
|
+
// !WITH_GENESYS
|
|
437
|
+
// return new Promise( resolve => {
|
|
438
|
+
//
|
|
439
|
+
// requestAnimationFrame( resolve );
|
|
440
|
+
//
|
|
441
|
+
// } );
|
|
369
442
|
|
|
370
443
|
}
|
|
371
444
|
|