Skip to content

feat(servicebag): Add SetInitFrameBudget to spread Init and Start over frames - #839

Open
oiisin wants to merge 3 commits into
Quenty:mainfrom
oiisin:users/oiisin/servicebag-init-frame-budget
Open

oiisin wants to merge 3 commits into
Quenty:mainfrom
oiisin:users/oiisin/servicebag-init-frame-budget

Conversation

@oiisin

@oiisin oiisin commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Adds ServiceBag:SetInitFrameBudget(seconds), which makes Init and Start wait a frame whenever the current frame has already spent the budget, so a bag with many services no longer initializes in one long frame. Dependencies still initialize first, and a service that yields in its own Init still errors. Timed with os.clock in a Studio playtest on a desktop PC (a client with ~150 services, two runs each): without a budget, Init and Start ran for 206–211 ms in a single frame; with a budget of 0.012 the longest stretch was 47–49 ms over 10–11 frames, though the bag finishes later (about 1.8 s instead of 0.2 s) because other join work shares those frames.

…r frames

ServiceBag:SetInitFrameBudget(seconds) makes Init and Start wait a frame whenever the current
frame has already spent the budget, so a large bag no longer initializes in one long frame.
Order is unchanged and a service that yields in its own Init still errors. GetFrameBudgetStats
reports how many frames were waited and the longest stretch of work.

On a client with ~150 services this turned a 260 ms join frame into stretches of at most ~51 ms
(budget 0.012).
…e budget set

A service whose Init errored was reported as having yielded and stopped the rest of Init, and if
it errored after a budget pause, Init never returned. Init is now caught, so an error is reported
the same way as without a budget and the bag carries on. GetFrameBudgetStats also returns 0 for
the stretch before Init has run.

This branch had an error being deployed

1 failed deployment
integration — c9f366c1 Deployed Oct 27, 2026 by oiisin via integration #713
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.

1 participant