Repository navigation
Conversation
This branch has not been 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.
Problem
createActorModelRuntime(packages/pi/src/models.ts) builds a newModelRuntimeon every call: it creates the runtime, registers the providers and refreshes the available models.createModelsinruntime.tscalls it each time an actor's harness is set up, so an actor that sleeps and wakes often pays this on every wake, although its options have not changed.Measured with only this package (no application code), 50 calls after 5 warm-up calls, one custom provider, three runs each:
In our hosted setup (many short actor wakes) this was about 12 % of the runner's CPU.
Change
createActorModelRuntime(options, credentials, actorId?)keeps one runtime per actor id in a module-level map (at most 256 actors, oldest evicted first).providers,apiKeys,scopedModels,modelandPI_OFFLINE(key order does not matter).actorIdnothing is cached and behaviour is exactly as before.createModelsnow passesc.actorId.Tests
New
packages/pi/tests/model-runtime-cache.test.ts:apiKeysormodelbuild a new runtime, reordered keys do not (fails on main);pnpm build,pnpm check-types,pnpm check-boundariespass;pnpm --filter @rivet-dev/pi test: 20 files, 133 tests pass;pnpm lintreports 5 existing warnings in files this PR does not touch.Notes for review