mirror of
https://github.com/langchain-ai/langgraphjs.git
synced 2026-07-22 17:15:25 -04:00
perf(langgraph): improve performance of checking for last superstep (#1625)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@langchain/langgraph": patch
|
||||
---
|
||||
|
||||
Fix performance regression due to deferred nodes
|
||||
@@ -92,6 +92,19 @@ export const increment = (current?: number) => {
|
||||
return current !== undefined ? current + 1 : 1;
|
||||
};
|
||||
|
||||
function triggersNextStep(
|
||||
updatedChannels: Set<string>,
|
||||
triggerToNodes: Record<string, string[]> | undefined
|
||||
) {
|
||||
if (triggerToNodes == null) return false;
|
||||
|
||||
for (const chan of updatedChannels) {
|
||||
if (triggerToNodes[chan]) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Avoids unnecessary double iteration
|
||||
function maxChannelMapVersion(
|
||||
channelVersions: Record<string, number | string>
|
||||
@@ -348,6 +361,7 @@ export function _applyWrites<Cc extends Record<string, BaseChannel>>(
|
||||
const channel = onlyChannels[chan];
|
||||
if (channel.isAvailable() && !updatedChannels.has(chan)) {
|
||||
const updated = channel.update([]);
|
||||
|
||||
if (updated && getNextVersion !== undefined) {
|
||||
checkpoint.channel_versions[chan] = getNextVersion(maxVersion);
|
||||
|
||||
@@ -359,12 +373,7 @@ export function _applyWrites<Cc extends Record<string, BaseChannel>>(
|
||||
}
|
||||
|
||||
// If this is (tentatively) the last superstep, notify all channels of finish
|
||||
if (
|
||||
bumpStep &&
|
||||
!Object.keys(triggerToNodes ?? {}).some((channel) =>
|
||||
updatedChannels.has(channel)
|
||||
)
|
||||
) {
|
||||
if (bumpStep && !triggersNextStep(updatedChannels, triggerToNodes)) {
|
||||
for (const chan in onlyChannels) {
|
||||
if (!Object.prototype.hasOwnProperty.call(onlyChannels, chan)) continue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user