feat(rivetkit): client-side KV preloading and startup metrics#4493
Merged
NathanFlurry merged 5 commits intomainfrom Mar 24, 2026
Merged
feat(rivetkit): client-side KV preloading and startup metrics#4493NathanFlurry merged 5 commits intomainfrom
NathanFlurry merged 5 commits intomainfrom
Conversation
Preload actor startup KV data client-side to reduce round-trips: - Existing actors: 1 RT (check persist) + 1 RT (parallel preload) = 2 RTs - New actors: 1 RT (check persist) + 1 RT (write initial state) = 2 RTs - Previously: 5+ sequential RTs during startup Add comprehensive startup metrics to /inspector/metrics: - Internal timing: checkPersistData, preloadKv, instantiate, loadState, restoreConnections, initQueue, initInspectorToken, flushWrites, setupDatabaseClient, initAlarms, onBeforeActorStart - User timing: createState, onCreate, onWake, createVars, dbMigrate - KV round-trip counter and total startup time WriteCollector batches new-actor init writes (persist data, queue metadata, inspector token) into a single kvBatchPut call. PreloadMap provides binary-search-based lookups for preloaded KV data with three-way return semantics (found/not-found/not-preloaded). SQLite VFS preload entries are passed through to createActorKvStore for cache hits during database initialization. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
🚅 Deployed to the rivet-pr-4493 environment in rivet-frontend
|
|
hello world |
Log every SQL query at debug level with duration and the number of KV operations it triggered. Covers both raw db() and drizzle db() paths. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Replace 3-way Uint8Array|null|undefined return with PreloadHit struct - Extract createPreloadMap() shared builder, dedup from engine driver - Export hasPrefix/binarySearchExists, remove duplicates in actor-driver - Remove `as any` cast via StartupTimingKey mapped type - Use try/finally for KV round-trip guard save/restore - Move kvStoreRef from closure to per-client WeakMap in db providers - Add startup logging convention to CLAUDE.md - Fix missing newline at EOF in actor-driver.ts
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Change startup metric types from "counter" to "gauge" (point-in-time values) - Fix stale preload data bug: clear preload before migrations, not after - Add pauseKvGuard option to #measureStartup, collapse guard boilerplate - Use perf internal/perf user log prefixes matching CLAUDE.md convention - Add comments noting preload hits are not tracked in KV metrics Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
/inspector/metricsendpoint covering all internal and user-facing startup phaseskvBatchPutviaWriteCollectorKey design decisions
kvGet+ 3xkvListPrefixto preload everything elsestartup_internal_*(framework) andstartup_user_*(callbacks) with flat key structure matching existing metrics formatTest plan
/inspector/metricsstartup fields (12 test runs across all encodings/client types)🤖 Generated with Claude Code