From cc3c8835f0ecdbf5e06fa57e04a29cf14284a700 Mon Sep 17 00:00:00 2001
From: Jonas Loos <33965649+JonasLoos@users.noreply.github.com>
Date: Sat, 24 Feb 2024 12:09:52 +0100
Subject: [PATCH] cache representations
---
index.html | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/index.html b/index.html
index 6fa8466..fbef5c8 100644
--- a/index.html
+++ b/index.html
@@ -118,6 +118,7 @@
H-Space similarity explorer
let current_model = null;
let available_positions = {};
let current_position = 'mid_block'; // assuming mid_block is always available
+const repr_cache = {};
const available_concepts = [];
const concepts = [];
const initial_concepts = [
@@ -172,13 +173,20 @@ H-Space similarity explorer
// helper function to load the representation
const getRepr = () => {
+ const url = `representations/${current_model.short}/${concept.name}/repr-${current_position}.bin`;
+ if (repr_cache[url]) {
+ concept.repr = repr_cache[url];
+ concept.repr_means = repr_cache[url+'_means'];
+ updateCanvasesWithLastClicked();
+ return;
+ }
concept.repr = null;
concept.repr_means = null;
concept.repr_loading_started = Date.now();
// backup current model name and position, as they might change during the fetch
const current_model_name_backup = current_model.name;
const current_position_backup = current_position;
- fetch(`representations/${current_model.short}/${concept.name}/repr-${current_position}.bin`)
+ fetch(url)
.then(response => response.arrayBuffer())
.then(buffer => {
@@ -205,6 +213,8 @@ H-Space similarity explorer
}
}
concept.repr_means = means;
+ repr_cache[url] = repr;
+ repr_cache[url+'_means'] = means;
// update convases as the representations are available now
updateCanvasesWithLastClicked();
})