Skip to content

fix: optimize stream/generate performance#287

Merged
omeraplak merged 14 commits intomainfrom
fix/optimize-memory-timeline-events
Jun 25, 2025
Merged

fix: optimize stream/generate performance#287
omeraplak merged 14 commits intomainfrom
fix/optimize-memory-timeline-events

Conversation

@omeraplak
Copy link
Member

fix: optimize streamText/generateText/generateObject/streamObject performance

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

Agent response times are slow due to blocking operations during stream initialization. Timeline events are published synchronously, causing delays, and memory operations for context loading block the stream start process. This results in:

  • Stream initialization taking 300-500ms
  • Slower response start times affecting user experience
  • Blocking delays during conversation setup and input saving

What is the new behavior?

Significantly improved agent response times by optimizing blocking operations during stream initialization:

  • Background Event Publishing: Timeline events now publish asynchronously, eliminating blocking delays
  • Memory Operations: Context loading optimized with background conversation setup and input saving
  • Stream initialization reduced to ~150-200ms (70-80% improvement)
  • Zero impact on conversation quality or history tracking
  • Perfect for production applications requiring fast AI interactions

fixes (issue)

Notes for reviewers

This optimization focuses on making blocking operations asynchronous without affecting the quality of conversation context or history tracking. The performance improvements are particularly noticeable in production environments where fast AI interactions are critical.

@changeset-bot
Copy link

changeset-bot bot commented Jun 21, 2025

🦋 Changeset detected

Latest commit: ba53977

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@voltagent/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@omeraplak omeraplak changed the title fix: optimize streamText/generateText/genereteObject/streamObject per… fix: optimize stream/generate performance Jun 21, 2025
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jun 21, 2025

Deploying voltagent with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3cab1ea
Status: ✅  Deploy successful!
Preview URL: https://13c13e28.voltagent.pages.dev
Branch Preview URL: https://fix-optimize-memory-timeline.voltagent.pages.dev

View logs

Copy link
Contributor

@zrosenbauer zrosenbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome to see!!!!!

A major item that concerns me:

Is this safe? Moving to queueing pattern means we need to consume all the queue events before we exist/close out a request. That means we need to execute that in the streamText and other calls, I didn't see that added (it might already but I don't belive so since this is new).

I would not merge until we have that as it could cause inconsistent memory data.

A couple pieces of additional feedback:

  • Could we add in benchmark tests with vitest to help verify we don't lost start up speed (https://vitest.dev/guide/features.html#benchmarking)
  • Anything that I know / believe we should fix in v1 / next major/minor bump I'm adding a TODO: comment so we can easily find them

@omeraplak
Copy link
Member Author

This is awesome to see!!!!!

A major item that concerns me:

Is this safe? Moving to queueing pattern means we need to consume all the queue events before we exist/close out a request. That means we need to execute that in the streamText and other calls, I didn't see that added (it might already but I don't belive so since this is new).

I would not merge until we have that as it could cause inconsistent memory data.

A couple pieces of additional feedback:

  • Could we add in benchmark tests with vitest to help verify we don't lost start up speed (https://vitest.dev/guide/features.html#benchmarking)
  • Anything that I know / believe we should fix in v1 / next major/minor bump I'm adding a TODO: comment so we can easily find them

Yep, definitely. I’m going to wrap it with a queue 🚀

@omeraplak omeraplak marked this pull request as draft June 21, 2025 21:58
@omeraplak omeraplak marked this pull request as ready for review June 23, 2025 15:43
Copy link
Contributor

@zrosenbauer zrosenbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm the only time we process the queue is when we drain it correct? Otherwise LGTM

@zrosenbauer zrosenbauer mentioned this pull request Jun 24, 2025
8 tasks
@omeraplak omeraplak merged commit 4136a9b into main Jun 25, 2025
5 of 8 checks passed
@omeraplak omeraplak deleted the fix/optimize-memory-timeline-events branch June 25, 2025 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants