A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: little perf improvement for workers

+34 -14
+2 -7
src/common/element.js
··· 3 3 import { html, render } from "lit-html"; 4 4 5 5 import { effect, signal } from "@common/signal.js"; 6 - import { 7 - rpc, 8 - workerLink, 9 - workerProxy, 10 - workerTunnel, 11 - } from "./worker.js"; 6 + import { rpc, workerLink, workerProxy, workerTunnel } from "./worker.js"; 12 7 import { BrowserPostMessageIo } from "./worker/rpc.js"; 13 8 14 9 /** ··· 366 361 const io = new BrowserPostMessageIo(() => msg.port2); 367 362 368 363 /** @type {undefined | RPCChannel<{}, ProxiedActions<Actions>>} */ 369 - const proxyChannel = new RPCChannel(io, { enableTransfer: true }); 364 + const proxyChannel = new RPCChannel(io, { enableTransfer: false }); 370 365 371 366 /** @type {ProxiedActions<Actions>} */ 372 367 const proxy = proxyChannel.getAPI();
+21 -4
src/common/worker.js
··· 1 - import { RPCChannel } from "@kunkun/kkrpc"; 1 + import { RPCChannel, transfer } from "@kunkun/kkrpc"; 2 2 import { getTransferables } from "@okikio/transferables"; 3 3 import { debounceMicrotask } from "@vicary/debounce-microtask"; 4 4 import { xxh32 } from "xxh32"; ··· 9 9 export { transfer } from "@kunkun/kkrpc"; 10 10 11 11 /** 12 - * @import {Announcement, Dependencies, MessengerRealm, ProxiedActions, Tunnel} from "./worker.d.ts" 12 + * @import {Track} from "@definitions/types.d.ts" 13 + * @import {Announcement, MessengerRealm, ProxiedActions, Tunnel} from "./worker.d.ts" 13 14 */ 14 15 15 16 //////////////////////////////////////////// ··· 53 54 } 54 55 55 56 /** 57 + * @param {Uint8Array} data 58 + * @returns {Track[]} 59 + */ 60 + export function tracksIn(data) { 61 + return JSON.parse(new TextDecoder().decode(data)); 62 + } 63 + 64 + /** 65 + * @param {Track[]} tracks 66 + */ 67 + export function tracksOut(tracks) { 68 + const buffer = new TextEncoder().encode(JSON.stringify(tracks)) 69 + return transfer(buffer, [buffer]); 70 + } 71 + 72 + /** 56 73 * @param {Worker | SharedWorker} worker 57 74 */ 58 75 export function workerLink(worker) { ··· 79 96 const io = new BrowserPostMessageIo(workerLinkCreator); 80 97 81 98 /** @type {undefined | RPCChannel<{}, ProxiedActions<Actions>>} */ 82 - const rpc = new RPCChannel(io, { enableTransfer: true }); 99 + const rpc = new RPCChannel(io, { enableTransfer: false }); 83 100 84 101 int_api = rpc.getAPI(); 85 102 } ··· 199 216 const io = new BrowserPostMessageIo(() => context); 200 217 201 218 /** @type {undefined | RPCChannel<Actions, {}>} */ 202 - return new RPCChannel(io, { enableTransfer: true, expose: actions }); 219 + return new RPCChannel(io, { enableTransfer: false, expose: actions }); 203 220 } 204 221 205 222 ////////////////////////////////////////////
+8 -2
src/components/orchestrator/scoped-tracks/element.js
··· 3 3 query, 4 4 queryOptional, 5 5 } from "@common/element.js"; 6 - import { computed, signal, untracked } from "@common/signal.js"; 6 + import { computed, signal } from "@common/signal.js"; 7 7 8 8 /** 9 - * @import {Playlist, Track} from "@definitions/types.d.ts" 9 + * @import {Track} from "@definitions/types.d.ts" 10 10 * @import {ProxiedActions} from "@common/worker.d.ts" 11 11 * @import {InputElement} from "@components/input/types.d.ts" 12 12 * @import {OutputElement} from "@components/output/types.d.ts" ··· 115 115 await customElements.whenDefined(output.localName); 116 116 if (scope) await customElements.whenDefined(scope.localName); 117 117 118 + const startTime = performance.now(); 119 + 118 120 // Watch tracks collection 119 121 this.effect(async () => { 120 122 const collection = output.tracks.collection(); 123 + console.log("🫠", collection); 121 124 if ((await this.isLeader()) === false) return; 122 125 const { availableTracks } = await this.#proxy.supplyAvailable(collection); 123 126 this.#tracksAvailable.value = availableTracks; ··· 151 154 const final = playlist 152 155 ? await this.#proxy.filterByPlaylist({ tracks, playlist }) 153 156 : tracks; 157 + 158 + const endTime = performance.now(); 159 + console.log("🚀", final, endTime - startTime); 154 160 155 161 this.#tracksFinal.set(final); 156 162 });
+3 -1
src/components/orchestrator/scoped-tracks/types.d.ts
··· 4 4 import type { Schema } from "@components/processor/search/types.d.ts"; 5 5 6 6 export type Actions = { 7 - filterByPlaylist(args: { tracks: Track[]; playlist: Playlist }): Promise<Track[]>; 7 + filterByPlaylist( 8 + args: { tracks: Track[]; playlist: Playlist }, 9 + ): Promise<Track[]>; 8 10 searchTracks(params: SearchParams<Schema>): Promise<Track[]>; 9 11 supplyAvailable(tracks: Track[]): Promise<{ availableTracks: Track[] }>; 10 12 };