Skip to content

Commit 26fcbb4

Browse files
committed
perf: eliminate per-row .map().join() in WorkerDO distinctPartition
Was creating an array + joining per row for key computation. Now uses direct string concatenation with pre-computed column list.
1 parent 23fbfff commit 26fcbb4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/worker-do.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,14 @@ export class WorkerDO extends DurableObject<WorkerEnv> implements WorkerDORpc {
217217
const seen = new Set<string>();
218218
const unique: Row[] = [];
219219

220+
const keyColumns = columns ?? Object.keys(rows[0] ?? {});
220221
for (const row of rows) {
221-
const key = columns
222-
? columns.map(c => { const v = row[c]; return v === null || v === undefined ? NULL_SENTINEL : String(v); }).join("\x00")
223-
: Object.values(row).map(v => v === null || v === undefined ? NULL_SENTINEL : String(v)).join("\x00");
222+
let key = "";
223+
for (let i = 0; i < keyColumns.length; i++) {
224+
if (i > 0) key += "\x00";
225+
const v = row[keyColumns[i]];
226+
key += v === null || v === undefined ? NULL_SENTINEL : String(v);
227+
}
224228
if (!seen.has(key)) {
225229
seen.add(key);
226230
unique.push(row);

0 commit comments

Comments
 (0)