@@ -72,6 +72,13 @@ type _GeoArrowSolidPolygonLayerProps = {
72
72
*/
73
73
_validate ?: boolean ;
74
74
75
+ /** If `true`, print metrics via `console.time`.
76
+ *
77
+ * This is primarily used for logging the time required for earcut
78
+ * triangulation.
79
+ */
80
+ metrics ?: boolean ;
81
+
75
82
/**
76
83
* URL to worker that performs earcut triangulation.
77
84
*
@@ -99,6 +106,7 @@ const ourDefaultProps: Pick<
99
106
| "_normalize"
100
107
| "_windingOrder"
101
108
| "_validate"
109
+ | "metrics"
102
110
| "earcutWorkerUrl"
103
111
| "earcutWorkerPoolSize"
104
112
> = {
@@ -109,6 +117,7 @@ const ourDefaultProps: Pick<
109
117
_windingOrder : "CCW" ,
110
118
111
119
_validate : true ,
120
+ metrics : false ,
112
121
113
122
// Note: set this to current version
114
123
earcutWorkerUrl :
@@ -244,7 +253,10 @@ export class GeoArrowSolidPolygonLayer<
244
253
}
245
254
246
255
const result : Uint32Array [ ] = new Array ( geometryColumn . data . length ) ;
247
- console . time ( "earcut" ) ;
256
+ const metricId = ( Date . now ( ) + Math . floor ( Math . random ( ) * 1000 ) ) . toString ( ) ;
257
+ if ( this . props . metrics ) {
258
+ console . time ( metricId ) ;
259
+ }
248
260
249
261
for (
250
262
let recordBatchIdx = 0 ;
@@ -270,7 +282,9 @@ export class GeoArrowSolidPolygonLayer<
270
282
}
271
283
272
284
await pool . completed ( ) ;
273
- console . timeEnd ( "earcut" ) ;
285
+ if ( this . props . metrics ) {
286
+ console . timeEnd ( metricId ) ;
287
+ }
274
288
275
289
return result ;
276
290
}
@@ -307,7 +321,10 @@ export class GeoArrowSolidPolygonLayer<
307
321
}
308
322
309
323
const result : Uint32Array [ ] = new Array ( geometryColumn . data . length ) ;
310
- console . time ( "earcut" ) ;
324
+ const metricId = ( Date . now ( ) + Math . floor ( Math . random ( ) * 1000 ) ) . toString ( ) ;
325
+ if ( this . props . metrics ) {
326
+ console . time ( metricId ) ;
327
+ }
311
328
312
329
for (
313
330
let recordBatchIdx = 0 ;
@@ -334,7 +351,9 @@ export class GeoArrowSolidPolygonLayer<
334
351
}
335
352
336
353
await pool . completed ( ) ;
337
- console . timeEnd ( "earcut" ) ;
354
+ if ( this . props . metrics ) {
355
+ console . timeEnd ( metricId ) ;
356
+ }
338
357
339
358
return result ;
340
359
}
0 commit comments