perf(langgraph): avoid calling maxChannelMapVersion twice (#1622)

This commit is contained in:
David Duong
2025-09-09 15:13:59 +02:00
committed by GitHub
parent 47e5df9411
commit 27934c0535
2 changed files with 10 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@langchain/langgraph": patch
---
Improve tick performance by calling `maxChannelMapVersion` only once
+5 -1
View File
@@ -272,10 +272,12 @@ export function _applyWrites<Cc extends Record<string, BaseChannel>>(
.filter((chan) => !RESERVED.includes(chan))
);
let usedNewVersion = false;
for (const chan of channelsToConsume) {
if (chan in onlyChannels && onlyChannels[chan].consume()) {
if (getNextVersion !== undefined) {
checkpoint.channel_versions[chan] = getNextVersion(maxVersion);
usedNewVersion = true;
}
}
}
@@ -294,7 +296,9 @@ export function _applyWrites<Cc extends Record<string, BaseChannel>>(
}
// Find the highest version of all channels
maxVersion = maxChannelMapVersion(checkpoint.channel_versions);
if (maxVersion != null && getNextVersion != null) {
maxVersion = usedNewVersion ? getNextVersion(maxVersion) : maxVersion;
}
const updatedChannels: Set<string> = new Set();
// Apply writes to channels