feat(langgraph): speed up prepareSingleTask by 20x (#1507)

This commit is contained in:
David Duong
2025-08-08 01:40:32 +02:00
committed by GitHub
parent 38de2726e3
commit 8f4acc0e39
3 changed files with 23 additions and 15 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@langchain/langgraph": patch
---
feat(langgraph): speed up prepareSingleTask by 20x
+2 -5
View File
@@ -840,11 +840,8 @@ export function _prepareSingleTask<
const seen = checkpoint.versions_seen[name] ?? {};
const triggers = proc.triggers
.filter((chan) => {
const result = readChannel(channels, chan, false, true);
const isEmptyChannelError =
// eslint-disable-next-line no-instanceof/no-instanceof
result instanceof Error &&
result.name === EmptyChannelError.unminifiable_name;
// here we're only checking if the channel is not empty
const isEmptyChannelError = !channels[chan].isAvailable();
return (
!isEmptyChannelError &&
(checkpoint.channel_versions[chan] ?? nullVersion) >
+16 -10
View File
@@ -4,19 +4,25 @@ import type {
ChannelVersions,
CheckpointMetadata,
} from "@langchain/langgraph-checkpoint";
import { CONFIG_KEY_CHECKPOINT_MAP } from "../../constants.js";
import { CONFIG_KEY_CHECKPOINT_MAP, START } from "../../constants.js";
export function getNullChannelVersion(currentVersions: ChannelVersions) {
const versionValues = Object.values(currentVersions);
const versionType =
versionValues.length > 0 ? typeof versionValues[0] : undefined;
let nullVersion: number | string | undefined;
if (versionType === "number") {
nullVersion = 0;
} else if (versionType === "string") {
nullVersion = "";
// Short circuit for commonly used channels such as __start__
// (used by StateGraph)
const startVersion = typeof currentVersions[START];
if (startVersion === "number") return 0;
if (startVersion === "string") return "";
// Defer back to obtaining a first key from channel versions
for (const key in currentVersions) {
if (!Object.prototype.hasOwnProperty.call(currentVersions, key)) continue;
const versionType = typeof currentVersions[key];
if (versionType === "number") return 0;
if (versionType === "string") return "";
break;
}
return nullVersion;
return undefined;
}
export function getNewChannelVersions(