Skip to content

Commit 3c79e69

Browse files
committed
perf(chunkImage): drop chunkStatus reactivity
This array does not need to be reactive. It being reactive is the source for some perf issues.
1 parent b374d20 commit 3c79e69

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/core/streaming/chunkImage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ export interface ChunkImage {
4343
callback: (info: ChunkImageEvents[T]) => void
4444
): void;
4545
isLoading: Ref<boolean>;
46-
chunkStatus: Ref<Array<ChunkStatus>>;
46+
chunkStatus: Array<ChunkStatus>;
4747
}

src/core/streaming/dicomChunkImage.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
ChunkStatus,
2323
ChunkImageEvents,
2424
} from '@/src/core/streaming/chunkImage';
25-
import { ComputedRef, Ref, computed, ref } from 'vue';
25+
import { ComputedRef, computed } from 'vue';
2626
import mitt, { Emitter } from 'mitt';
2727

2828
const { fastComputeRange } = vtkDataArray;
@@ -74,16 +74,16 @@ export default class DicomChunkImage implements ChunkImage {
7474
private events: Emitter<ChunkImageEvents>;
7575
public imageData: Maybe<vtkImageData>;
7676
public dataId: Maybe<string>;
77-
public chunkStatus: Ref<ChunkStatus[]>;
77+
public chunkStatus: ChunkStatus[];
7878
public isLoading: ComputedRef<boolean>;
7979

8080
constructor() {
8181
this.chunks = [];
8282
this.chunkListeners = [];
8383
this.dataId = null;
84-
this.chunkStatus = ref([]);
84+
this.chunkStatus = [];
8585
this.isLoading = computed(() =>
86-
this.chunkStatus.value.some(
86+
this.chunkStatus.some(
8787
(status) =>
8888
status !== ChunkStatus.Loaded && status !== ChunkStatus.Errored
8989
)
@@ -112,7 +112,7 @@ export default class DicomChunkImage implements ChunkImage {
112112
this.chunks.length = 0;
113113
this.imageData = null;
114114
this.dataId = null;
115-
this.chunkStatus.value = [];
115+
this.chunkStatus = [];
116116
this.thumbnailCache = new WeakMap();
117117
}
118118

@@ -150,7 +150,7 @@ export default class DicomChunkImage implements ChunkImage {
150150
// save the newly sorted chunk order
151151
[this.dataId, this.chunks] = volumes[0];
152152

153-
this.chunkStatus.value = this.chunks.map((chunk) => {
153+
this.chunkStatus = this.chunks.map((chunk) => {
154154
switch (chunk.state) {
155155
case ChunkState.Init:
156156
case ChunkState.MetaLoading:
@@ -255,7 +255,7 @@ export default class DicomChunkImage implements ChunkImage {
255255
dims[0] * dims[1] * scalars.getNumberOfComponents() * chunkIndex;
256256
pixelData.set(result.image.data as TypedArray, offset);
257257

258-
const rangeAlreadyInitialized = this.chunkStatus.value.some(
258+
const rangeAlreadyInitialized = this.chunkStatus.some(
259259
(status) => status === ChunkStatus.Loaded
260260
);
261261

@@ -275,22 +275,21 @@ export default class DicomChunkImage implements ChunkImage {
275275
scalars.setRange({ min: newMin, max: newMax }, comp);
276276
}
277277

278+
this.chunkStatus[chunkIndex] = ChunkStatus.Loaded;
278279
this.events.emit('chunkLoaded', {
279280
chunk,
280281
updatedExtent: [0, dims[0] - 1, 0, dims[1] - 1, chunkIndex, chunkIndex],
281282
});
282283

283-
this.chunkStatus.value[chunkIndex] = ChunkStatus.Loaded;
284-
285284
this.imageData.modified();
286285
}
287286

288287
private onChunkErrored(chunkIndex: number, err: unknown) {
288+
this.chunkStatus[chunkIndex] = ChunkStatus.Errored;
289289
this.events.emit('chunkErrored', {
290290
chunk: this.chunks[chunkIndex],
291291
error: err,
292292
});
293-
this.chunkStatus.value[chunkIndex] = ChunkStatus.Errored;
294293
}
295294

296295
private updateDicomStore() {

0 commit comments

Comments
 (0)