connect: expose light mode and confirmed reads #22
Labels
No labels
area:defold
area:docs
area:infra
area:protocol
area:testing
kind:bug
kind:chore
phase:breadth
phase:core
phase:hardening
phase:slice
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
yuris/spacetimedb-defold#22
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
connectaccepts no equivalent of the official SDKs'withLightModeandwithConfirmedReads. Both are single query parameters on the subscribe URL, and both are supported onv1.json.spacetimedb.What they do
Verified in SpacetimeDB v2.8.2 source:
?light=true→ClientConfig.tx_update_full = !light(crates/client-api/src/routes/subscribe.rs:204-208). The server then sendsTransactionUpdateLight— rows only, no status, timestamp, caller identity or reducer info — for transactions the client did not itself call. The caller always receives a full update regardless (module_subscription_manager.rs:1962-1964), so a client's own reducer callbacks are unaffected.?confirmed=true|false→ holds updates until they are durable (subscribe.rs:107-114). Default isfalseon the v1 protocol.The SDK already handles
TransactionUpdateLight(stdb/connection.lua:324), so light mode needs no new message handling — only the ability to ask for it.Why light mode is worth having here
It is a bandwidth and parse win, and parse cost is the one that bites in Lua: every non-caller transaction currently carries
caller_identity,caller_connection_id,reducer_call(name, id, args, request_id),energy_quanta_usedandtotal_host_execution_durationthat most games read none of. On a busy module with many players, that is per-message JSON a pure-Lua decoder pays for on the main thread, on mobile, every frame a transaction lands.confirmedis the narrower one: it trades latency for durability, which matters for anything the player perceives as committed (a purchase, a match result) and is wrong for high-frequency position updates.Proposed change
Two
connectoptions threaded onto the URL, defaulting to current behaviour so nothing changes for existing callers:lightfalse?light=trueconfirmed_readsnil?confirmed=true/falsewhen set; omitted otherwiseThe URL assembly belongs next to
stdb.with_token, which already knows how to append a parameter and is unit-tested (dev/test/test_init.lua:24-25).Watch two things:
with_token. The token is appended as?token=on HTML5; a second parameter must use&. The existing helper handles one parameter, not composition — that is the actual work in this issue.confirmedis tri-state. Absent,true, andfalseare three distinct requests; a boolean default offalsewould silently start sending?confirmed=falsewhere the SDK currently sends nothing. Keepnilmeaning "do not mention it".Acceptance
Unit tests in
dev/test/test_init.luacovering: light alone, confirmed alone, both, both plus a token (proving?/&composition), and the default case emitting a byte-identical URL to today's.Light mode also wants one conformance assertion, since it is the only way to prove the server actually honoured it: with
light = true, a transaction caused by another connection should arrive asTransactionUpdateLight. That needs a second client in the harness, so it may be worth deferring the conformance half and shipping the option with unit coverage only — say so explicitly rather than leaving it ambiguous.Priority
Medium. Neither is required for correctness,
lightis a real cost saving for the exact platform this SDK targets, and both are cheap. Good 1.0 material, not a blocker.