SpacetimeDB
SpacetimeDB copied to clipboard
`call_reducer_with_tx`: move work before/after tx lock aquire/release
Description of Changes
Most of these were noticeable in the 380 CCU flame graph.
- Create
ctx& clonetx_slotbefore takingtxlock. - Move an allocation before taking
txlock. - Move
energy_monitor.record_reducer(..)to after releasingtxlock. - Move tracing & metrics work to after releasing
txlock. - Move actual dropping of
Arc<ModuleEvent>(last referent) to outside ofblocking_broadcast_event, reducing the time thesubscriptions.read()lock andtxlock is held. - Move work done by
record_metricsafter tx/subscription locks have been released. - Tweak
merge_apply_insertsandmerge_apply_deletesto update metrics at most once per table.
API and ABI breaking changes
None
Expected complexity level and risk
3 - We've had deadlocks and threading issues in this code path before, so review the logic with care.
Testing
A playtest would be good to run before merging, primarily for safety reasons.