Repository navigation
perf: run database routes beside the database - #167
Merged
Merged
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Production search takes 1.4–3.4s per query, against ~250ms locally on the same database. The response header shows why:
x-vercel-id: iad1::sin1. Requests enter Vercel's edge in Washington, but functions execute in sin1 (Singapore), the project's default function region, while Neon is in us-east-2 (Ohio). Every database round trip crosses the Pacific twice. Even keyword-only search, with no embedding call, took 1.5s.This pins only the routes that talk to Neon to iad1 (about 10ms from us-east-2) with Next's per-route
preferredRegion: /api/search, /api/thoughts, /thoughts (its hourly ISR regeneration queries Neon), /tweet and /api/tweet. Everything else keeps the project default. View counts use Upstash, whose region I can't see, so they're left alone.Measurements from the [preview] deploy will follow in a comment. If you'd rather move the whole project, that's a Vercel dashboard setting (Settings → Functions → Region), but it affects every function.
tsc, 592 tests and knip pass.
til: x-vercel-id reads edge::function::id. The second hop is where your code ran, and a mismatch with your database's region costs a cross-ocean round trip per query.