Skip to content

Commit c0f29da

Browse files
committed
perf(langgraph): avoid calling maxChannelMapVersion twice
1 parent d35db59 commit c0f29da

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

libs/langgraph/src/pregel/algo.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,12 @@ export function _applyWrites<Cc extends Record<string, BaseChannel>>(
272272
.filter((chan) => !RESERVED.includes(chan))
273273
);
274274

275+
let usedNewVersion = false;
275276
for (const chan of channelsToConsume) {
276277
if (chan in onlyChannels && onlyChannels[chan].consume()) {
277278
if (getNextVersion !== undefined) {
278279
checkpoint.channel_versions[chan] = getNextVersion(maxVersion);
280+
usedNewVersion = true;
279281
}
280282
}
281283
}
@@ -294,7 +296,9 @@ export function _applyWrites<Cc extends Record<string, BaseChannel>>(
294296
}
295297

296298
// Find the highest version of all channels
297-
maxVersion = maxChannelMapVersion(checkpoint.channel_versions);
299+
if (maxVersion != null && getNextVersion != null) {
300+
maxVersion = usedNewVersion ? getNextVersion(maxVersion) : maxVersion;
301+
}
298302

299303
const updatedChannels: Set<string> = new Set();
300304
// Apply writes to channels

0 commit comments

Comments
 (0)