Skip to content

Run shutdown Ref.sets sequentially#116

Closed
EtaCassiopeia wants to merge 1 commit into
mainfrom
refactor/sequential-shutdown
Closed

Run shutdown Ref.sets sequentially#116
EtaCassiopeia wants to merge 1 commit into
mainfrom
refactor/sequential-shutdown

Conversation

@EtaCassiopeia
Copy link
Copy Markdown
Owner

Summary

FeatureFlags#shutdown was running five Ref.set calls via ZIO.collectAllParDiscard. Atomic Ref.set is a lock-free nanosecond-scale operation, so the fork/join overhead of parallel execution exceeds the work itself. A sequential *> chain is clearer and avoids fiber creation.

// Before
ZIO.collectAllParDiscard(List(
  state.statusRef.set(ProviderStatus.NotReady),
  state.hooksRef.set(List.empty),
  state.globalContextRef.set(EvaluationContext.empty),
  state.clientContextRef.set(EvaluationContext.empty),
  state.trackRecorder.set(List.empty)
)) *> state.eventHub.shutdown *> ZIO.attemptBlocking(api.shutdown()).ignore

// After
state.statusRef.set(ProviderStatus.NotReady) *>
  state.hooksRef.set(List.empty) *>
  state.globalContextRef.set(EvaluationContext.empty) *>
  state.clientContextRef.set(EvaluationContext.empty) *>
  state.trackRecorder.set(List.empty) *>
  state.eventHub.shutdown *>
  ZIO.attemptBlocking(api.shutdown()).ignore

Pure refactor; no behavior change (these Refs are independent so any order is correct).

Credit

Spotted in #110 by @guizmaii.

Test plan

  • All tests pass (340 + 99 + 170)
  • scalafmtCheckAll clean

@EtaCassiopeia
Copy link
Copy Markdown
Owner Author

Tested independently; closing in favor of #110.

@EtaCassiopeia EtaCassiopeia deleted the refactor/sequential-shutdown branch May 13, 2026 01:52
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