Skip to content

Commit 7390bed

Browse files
committed
chore: push some debug info about cache size and use TypedArray
1 parent f1b1786 commit 7390bed

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

src/data/data2d/Spectrum2D/contours.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,20 @@ function getContours(options: ContoursCalcOptions) {
281281
// return createEmptyResult(levelValues);
282282
// }
283283

284-
const contours: BasicContour[] = [];
285284
const levelValuesToCalculate: number[] = [];
286285
const levelsToCalculate: number[] = [];
287286
for (let i = 0; i < levels.length; i++) {
288287
const level = levels[i];
289-
if (cache.has(level)) {
290-
contours.push(cache.get(level) as BasicContour);
291-
} else {
288+
if (!cache.has(level)) {
292289
levelValuesToCalculate.push(levelValues[i]);
293290
levelsToCalculate.push(level);
294291
}
295292
}
293+
console.log({
294+
width: data.z.length,
295+
height: data.z[0].length,
296+
levelsToCalculate,
297+
});
296298

297299
const conrec = initializeConrec(data);
298300
console.time('contour');
@@ -313,9 +315,30 @@ function getContours(options: ContoursCalcOptions) {
313315

314316
for (const conrecContour of conrecContours) {
315317
const index = levelValuesToCalculate.indexOf(conrecContour.zValue);
316-
cache.set(levelsToCalculate[index], conrecContour);
318+
cache.set(levelsToCalculate[index], {
319+
zValue: conrecContour.zValue,
320+
lines: Float32Array.from(conrecContour.lines),
321+
});
322+
}
323+
324+
const contours: BasicContour[] = [];
325+
for (let i = 0; i < levels.length; i++) {
326+
const level = levels[i];
327+
if (cache.has(level)) {
328+
contours.push(cache.get(level) as BasicContour);
329+
}
330+
}
331+
332+
let nbLines = 0;
333+
let maxNbLines = 0;
334+
for (const cacheItem of cache) {
335+
nbLines += cacheItem[1].lines.length;
336+
if (cacheItem[1].lines.length > maxNbLines) {
337+
maxNbLines = cacheItem[1].lines.length;
338+
}
339+
// console.log(cacheItem[1].zValue, cacheItem[1].lines.length);
317340
}
318-
contours.push(...conrecContours);
341+
console.log({ nbLines, maxNbLines, cacheSize: cache.size });
319342

320343
return {
321344
contours,

0 commit comments

Comments
 (0)