Repository navigation
fix: write log files off the main thread - #57
Merged
Merged
Conversation
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
marked this pull request as ready for review
September 24, 2026 10:24
karolb-proexe
approved these changes
Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Defaultwould not do, because appending is a seek followed by a write and two of those overlapping on one file lose a line.JsonLoggerFacilitybuilds its scopes through the same helper and inherits this.Screenshots / Recordings 📷
How to Test 🐛
./gradlew jvmTest iosSimulatorArm64Test macosArm64TestFileLoggerFacilitySharedFileTestcases fail onmainwithDispatchers.Main was accessed when the platform dispatcher was absentFileLoggerFacilityCostTestprints the per-write cost: 33 us per append on an iOS simulator, 500 of them in 17 msReferences 🔗