Skip to content

Commit a527fc7

Browse files
authored
perf(langgraph): short-circuit interrupt detection to speed up tick (#1624)
1 parent 27934c0 commit a527fc7

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

.changeset/many-bees-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@langchain/langgraph": patch
3+
---
4+
5+
Improve tick performance by detecting interrupts faster within a tick.

libs/langgraph/src/pregel/algo.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
PREVIOUS,
5555
CACHE_NS_WRITES,
5656
CONFIG_KEY_RESUME_MAP,
57+
START,
5758
} from "../constants.js";
5859
import {
5960
Call,
@@ -116,15 +117,23 @@ export function shouldInterrupt<N extends PropertyKey, C extends PropertyKey>(
116117
const seen = checkpoint.versions_seen[INTERRUPT] ?? {};
117118

118119
let anyChannelUpdated = false;
119-
for (const chan in checkpoint.channel_versions) {
120-
if (
121-
!Object.prototype.hasOwnProperty.call(checkpoint.channel_versions, chan)
122-
)
123-
continue;
124120

125-
if (checkpoint.channel_versions[chan] > (seen[chan] ?? nullVersion)) {
126-
anyChannelUpdated = true;
127-
break;
121+
if (
122+
(checkpoint.channel_versions[START] ?? nullVersion) >
123+
(seen[START] ?? nullVersion)
124+
) {
125+
anyChannelUpdated = true;
126+
} else {
127+
for (const chan in checkpoint.channel_versions) {
128+
if (
129+
!Object.prototype.hasOwnProperty.call(checkpoint.channel_versions, chan)
130+
)
131+
continue;
132+
133+
if (checkpoint.channel_versions[chan] > (seen[chan] ?? nullVersion)) {
134+
anyChannelUpdated = true;
135+
break;
136+
}
128137
}
129138
}
130139

0 commit comments

Comments
 (0)