Skip to content

Commit cc22e69

Browse files
authored
fix: Only log metrics if desired, opt-in (#146)
1 parent 343eacf commit cc22e69

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/layers/solid-polygon-layer.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ type _GeoArrowSolidPolygonLayerProps = {
7272
*/
7373
_validate?: boolean;
7474

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+
7582
/**
7683
* URL to worker that performs earcut triangulation.
7784
*
@@ -99,6 +106,7 @@ const ourDefaultProps: Pick<
99106
| "_normalize"
100107
| "_windingOrder"
101108
| "_validate"
109+
| "metrics"
102110
| "earcutWorkerUrl"
103111
| "earcutWorkerPoolSize"
104112
> = {
@@ -109,6 +117,7 @@ const ourDefaultProps: Pick<
109117
_windingOrder: "CCW",
110118

111119
_validate: true,
120+
metrics: false,
112121

113122
// Note: set this to current version
114123
earcutWorkerUrl:
@@ -244,7 +253,10 @@ export class GeoArrowSolidPolygonLayer<
244253
}
245254

246255
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+
}
248260

249261
for (
250262
let recordBatchIdx = 0;
@@ -270,7 +282,9 @@ export class GeoArrowSolidPolygonLayer<
270282
}
271283

272284
await pool.completed();
273-
console.timeEnd("earcut");
285+
if (this.props.metrics) {
286+
console.timeEnd(metricId);
287+
}
274288

275289
return result;
276290
}
@@ -307,7 +321,10 @@ export class GeoArrowSolidPolygonLayer<
307321
}
308322

309323
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+
}
311328

312329
for (
313330
let recordBatchIdx = 0;
@@ -334,7 +351,9 @@ export class GeoArrowSolidPolygonLayer<
334351
}
335352

336353
await pool.completed();
337-
console.timeEnd("earcut");
354+
if (this.props.metrics) {
355+
console.timeEnd(metricId);
356+
}
338357

339358
return result;
340359
}

0 commit comments

Comments
 (0)