@@ -27,6 +27,17 @@ export type IdetikContext = {
2727 chunkManager : ChunkManager ;
2828} ;
2929
30+ // JS heap usage from the non-standard performance.memory API.
31+ // Chromium only, undefined where the API is unavailable.
32+ type MemoryStats = {
33+ cpuChunkBytes : number ;
34+ cpuChunkCount : number ;
35+ gpuTextureBytes : number ;
36+ gpuTextureCount : number ;
37+ jsHeapUsedBytes ?: number ;
38+ jsHeapLimitBytes ?: number ;
39+ } ;
40+
3041export class Idetik {
3142 private readonly chunkManager_ : ChunkManager ;
3243 private readonly context_ : IdetikContext ;
@@ -137,6 +148,22 @@ export class Idetik {
137148 return this . chunkManager_ . queueStats ;
138149 }
139150
151+ public get memoryStats ( ) : MemoryStats {
152+ const perf = (
153+ performance as Performance & {
154+ memory ?: { usedJSHeapSize : number ; jsHeapSizeLimit : number } ;
155+ }
156+ ) . memory ;
157+
158+ return {
159+ ...this . chunkManager_ . memoryStats ,
160+ gpuTextureBytes : this . renderer_ . gpuTextureBytes ,
161+ gpuTextureCount : this . renderer_ . gpuTextureCount ,
162+ jsHeapUsedBytes : perf ?. usedJSHeapSize ,
163+ jsHeapLimitBytes : perf ?. jsHeapSizeLimit ,
164+ } ;
165+ }
166+
140167 public get renderedObjects ( ) {
141168 return this . renderer_ . renderedObjects ;
142169 }
0 commit comments