Skip to content

Commit

Permalink
perf(track): Persist GoslingTrackModels (#1044)
Browse files Browse the repository at this point in the history
* perf: persist GoslingTrackModels

* perf: replace structuredClone
  • Loading branch information
etowahadams authored Feb 22, 2024
1 parent 9ecd4d3 commit 560d121
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tracks/gosling-track/gosling-track-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class GoslingTrackModel {
this.dataAggregated = data; // this will be updated after validity of the spec is checked

this.specOriginal = spec;
this.specComplete = structuredClone(spec);
this.specComplete = JSON.parse(JSON.stringify(spec));

this.channelScales = {};

Expand Down
14 changes: 14 additions & 0 deletions src/tracks/gosling-track/gosling-track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ const factory: PluginTrackFactory<Tile, GoslingTrackOptions> = (HGC, context, op
#loadingText = new HGC.libraries.PIXI.Text('', loadingTextStyle);
prevVisibleAndFetchedTiles?: Tile[];
resolvedTracks: SingleTrack[] | undefined;
// This is used to persist processed tile data across draw() calls.
#processedTileMap: WeakMap<Tile, boolean> = new WeakMap();

/* *
*
Expand Down Expand Up @@ -416,6 +418,8 @@ const factory: PluginTrackFactory<Tile, GoslingTrackOptions> = (HGC, context, op
this.getResolvedTracks(true); // force update
this.clearMouseEventData();
this.textsBeingUsed = 0;
// Without this, tracks with the same ID between specs will not be redrawn
this.#processedTileMap = new WeakMap();

this.processAllTiles(true);
this.draw();
Expand Down Expand Up @@ -555,6 +559,11 @@ const factory: PluginTrackFactory<Tile, GoslingTrackOptions> = (HGC, context, op
this.tileSize = this.tilesetInfo?.tile_size ?? 1024;

const tiles = this.visibleAndFetchedTiles();
// If we have already processed all tiles, we don't need to do anything
// this.#processedTileMap contains all of data needed to draw
if (tiles.every(tile => this.#processedTileMap.get(tile) !== undefined)) {
return;
}

// generated tabular data
tiles.forEach(tile => this.#generateTabularData(tile, force));
Expand All @@ -571,6 +580,11 @@ const factory: PluginTrackFactory<Tile, GoslingTrackOptions> = (HGC, context, op
if (flatTileData.length !== 0) {
this.options.siblingIds.forEach(id => publish('rawData', { id, data: flatTileData }));
}

// Record processed tiles so that we don't process them again
tiles.forEach(tile => {
this.#processedTileMap.set(tile, true);
});
}

/**
Expand Down

0 comments on commit 560d121

Please sign in to comment.