Optimize explore data worker transfer with lightweight video objects

- Implements `toLightweightVideo` helper in `js/services/exploreDataService.js` to strip large fields (content, signatures, etc.) from video objects before sending to the worker.
- Updates `buildWatchHistoryTagCounts` and `buildTagIdf` to use lightweight objects.
- Adds `tests/services/exploreDataService.optimization.test.mjs` to verify correctness.
- Adds `benchmarks/worker_transfer_lightweight_bench.js` demonstrating ~40% improvement in transfer time.

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-02-11 17:15:25 +00:00
1 parent 1d2118d15e
commit 99e904d7c1
3 files changed
+229 -2

No files matched your search

+36 -2
View File
@@ -32,6 +32,33 @@ function runWorkerTask(type, payload) {
});
}
export function toLightweightVideo(video) {
if (!video || typeof video !== "object") {
return null;
}
const lightweight = {
id: video.id,
kind: video.kind,
pubkey: video.pubkey,
nip71: video.nip71,
tags: [],
};
if (Array.isArray(video.tags)) {
for (const t of video.tags) {
if (Array.isArray(t) && t.length >= 2) {
const type = t[0];
if (type === "d" || type === "t") {
lightweight.tags.push(t);
}
}
}
}
return lightweight;
}
export async function buildWatchHistoryTagCounts({
watchHistoryService,
nostrService,
@@ -51,11 +78,16 @@ export async function buildWatchHistoryTagCounts({
items = [];
}
const videosMap =
const sourceMap =
nostrService && typeof nostrService.getVideosMap === "function"
? nostrService.getVideosMap()
: new Map();
const videosMap = new Map();
for (const [id, video] of sourceMap) {
videosMap.set(id, toLightweightVideo(video));
}
try {
const counts = await runWorkerTask('CALC_HISTORY_COUNTS', { items, videosMap });
return counts instanceof Map ? counts : new Map();
@@ -71,8 +103,10 @@ export async function buildTagIdf({ videos } = {}) {
return new Map();
}
const lightweightVideos = list.map(toLightweightVideo);
try {
const idf = await runWorkerTask('CALC_IDF', { videos: list });
const idf = await runWorkerTask('CALC_IDF', { videos: lightweightVideos });
return idf instanceof Map ? idf : new Map();
} catch (error) {
devLogger.warn("[exploreData] Worker failed to calculate IDF:", error);