Skip to content

fix: write log files off the main thread - #57

Merged
LaStrada merged 2 commits into
mainfrom
fix/file-logging-off-the-main-thread
Sep 24, 2026
Merged

LaStrada merged 2 commits into
mainfrom
fix/file-logging-off-the-main-thread

Conversation

@LaStrada

Copy link
Copy Markdown
Member

Description ✏️

The convenience constructors built their scope over Dispatchers.Main, so appending — open a handle, seek to the end, write, close — ran on the UI thread. It also meant those constructors threw wherever no main dispatcher exists, which is every JVM and native test.

One dispatcher with a parallelism of one serves them all: the writes move off the main thread and stay ordered against each other. Plain Default would not do, because appending is a seek followed by a write and two of those overlapping on one file lose a line.

JsonLoggerFacility builds its scopes through the same helper and inherits this.

Screenshots / Recordings 📷

How to Test 🐛

  • ./gradlew jvmTest iosSimulatorArm64Test macosArm64Test
  • The three new FileLoggerFacilitySharedFileTest cases fail on main with Dispatchers.Main was accessed when the platform dispatcher was absent
  • FileLoggerFacilityCostTest prints the per-write cost: 33 us per append on an iOS simulator, 500 of them in 17 ms

References 🔗

The convenience constructors handed the facility a scope over Dispatchers.Main,
so appending - which opens a handle, seeks to the end, writes and closes - ran
on the UI thread. It also meant those constructors threw wherever no main
dispatcher exists, which is every JVM and native test.

One dispatcher with a parallelism of one serves them all, so the writes move
off the main thread while staying ordered against each other. Plain Default
would not do: appending is a seek followed by a write, and two of those
overlapping on one file lose a line.

Measured on an iOS simulator: 33 us per append, 500 of them in 17 ms.

JsonLoggerFacility builds its scopes through the same helper and inherits this.
@LaStrada LaStrada self-assigned this Sep 24, 2026
@LaStrada
LaStrada marked this pull request as ready for review September 24, 2026 10:24
@LaStrada
LaStrada requested review from a team as code owners September 24, 2026 10:24
@LaStrada
LaStrada merged commit c2a676b into main Sep 24, 2026
2 checks passed
@LaStrada
LaStrada deleted the fix/file-logging-off-the-main-thread branch September 24, 2026 18:03
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.

2 participants