SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

`call_reducer_with_tx`: move work before/after tx lock aquire/release

Open Centril opened this issue 1 year ago • 1 comments

Description of Changes

Most of these were noticeable in the 380 CCU flame graph.

  1. Create ctx & clone tx_slot before taking tx lock.
  2. Move an allocation before taking tx lock.
  3. Move energy_monitor.record_reducer(..) to after releasing tx lock.
  4. Move tracing & metrics work to after releasing tx lock.
  5. Move actual dropping of Arc<ModuleEvent> (last referent) to outside of blocking_broadcast_event, reducing the time the subscriptions.read() lock and tx lock is held.
  6. Move work done by record_metrics after tx/subscription locks have been released.
  7. Tweak merge_apply_inserts and merge_apply_deletes to 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.

Centril avatar Apr 16 '24 09:04 Centril

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 03 '25 18:05 CLAassistant