跳到正文
Vercel Blog(vercel.com)· Peter Wielander·· 6 天前品質評分63

Vercel Workflow SDK 5.8 換上新引擎,工作流程最高快 12 倍

Workflow is 10x faster, again

重點導讀

AI 助理和其他工作流程常要分好幾步處理事情,步驟之間的等待時間會拖慢整體速度。

  • Vercel 的 Workflow SDK 5.8 換上新的執行引擎,基準測試中,步驟間的額外等待從 85 毫秒降到 7 毫秒。
  • 同時跑 256 個步驟時,函式在步驟工作以外花的時間也少了 14 倍。升級到 workflow@5.8.0 後,新工作流程預設使用新引擎,已開始的流程則會繼續用原本版本。新引擎會重試部分步驟,因此適合重試的步驟應盡量設計成重複執行也安全。
  • 像寄電子郵件這種重試可能造成重複寄送的步驟,可設為不重試。

AI 伴隨問答

自備 Key 深度分析

針對這篇報導有疑問?可直接點選快捷問題或向 AI 追問背景脈絡與技術細節:

正文

Workflow SDK 5.8 runs workflows on a new execution engine, rebuilt for performance. Step-to-step latency is 12x lower, and large fan-outs, like running 256 steps in parallel, use 14x less function time outside your step code. This directly improves turn times for durable AI agents, among many other improvements.

To get the new engine, upgrade to workflow@5.8.0 or later. New runs will use the new engine by default, and runs already started on an older version will safely keep running on that version. Make sure your steps are idempotent where possible to get the most out of this upgrade.

Copy link to headingDrastically reduced overhead

In our benchmarks comparing 5.2.0 to 5.8.0, p75 step-to-step overhead fell from 85 ms to 7 ms. The median run, including 102 seconds of step work, finished in 111 seconds instead of 3.0 minutes. Running 256 parallel steps in a fan-out added 5.5× less overhead, 2.5 seconds instead of 13.5 seconds, and the median run spent 14× less time in functions beyond the steps' own work, 105 seconds instead of 1,446. A five-turn agent loop that streams its tokens through durable streams and calls tools added 0.9 seconds of overhead instead of 3.0 seconds, 3.3× less. Consult the benchmarks page for how we measure these numbers.

Resuming after 1 second idle time went from 425 ms to 184 ms, 2.3× faster. Resumptions more than 5 seconds out might see slightly larger overhead. You can choose to keep functions warm for longer to optimize time-to-resume at the cost of additional compute time.

Copy link to headingSpeculative execution for retryable steps

Many of the above benefits rely on speculative execution of Steps. Only Steps that are idempotent can be run in this way. A step that passes its stepId as an idempotency key, like the Stripe charge below, is already safe and needs no changes. If your step is sensitive and can't be retried, mark it with maxRetries = 0 to opt out and ensure it still runs at most once.

You should already be making Steps idempotent wherever possible, or flag them with maxRetries = 0, to ensure Workflow SDK doesn't re-run your Steps when it's not safe to do so.

steps.ts

import { getStepMetadata } from "workflow";

// Idempotent: stepId stays the same across retries and speculative

// re-runs, so Stripe creates one charge. No changes needed.

async function chargeUser(userId: string, amount: number) {

"use step";

const { stepId } = getStepMetadata();

await stripe.charges.create(

{ amount, currency: "usd", customer: userId },

{ idempotencyKey: stepId },

);

}

// Hard to make idempotent: SMTP has no idempotency key, so a second

// attempt sends a second email. Opt out of speculation and retries.

async function sendReceiptEmail(to: string, orderId: string) {

"use step";

await smtp.sendMail({ to, subject: `Your receipt for order ${orderId}` });

}

sendReceiptEmail.maxRetries = 0;

Copy link to headingGet started

Upgrade to workflow@5.8.0. To keep creating runs on the previous engine after upgrading, set WORKFLOW_SPEC_VERSION=8. If you're on 4.x, start with the upgrade guide, since v5 is a major release.

terminal

npm install workflow@latest

Using a third-party World? All Worlds maintained by Vercel already support the new engine. A third-party World needs to support World spec version 9 before upgrading gives you any of these improvements. Until it does, new runs keep using the previous engine.

來源: Vercel Blog (vercel.com)
開啟原文

讀者討論

理性交流 · 即時討論