telemetry-ios
telemetry-ios copied to clipboard
Move all disk I/O off-main
A single non-concurrent background thread for disk management is a common pattern to use here. Lends itself well to rate-limiting the I/O.
@justindarc I am thinking of working on this next.
It appears straightforward to wrap the entire lib to run on a single concurrent background queue (no big refactor is needed to do this that I can see). I see it as changing the thread it runs on from main to off-main.
The lib only has these public
access functions which need to have guarded memory access:
- Telemetry.default and Telemetry.init() [actually, init functions don't need any changes]
- Telemetry.add()
- Telemetry.recordEvent()
- Telemetry.configuration
Everything else in Telemetry.swift can be internal access level AFAIK.
I don't see any issues with avoiding shared mem access in those functions, add() and recordEvent() could post an immutable object to the background queue. Telemetry.configuration could be changed to a struct and internally accessed only through a getter that returns an immutable copy (and a setter that takes immutable input).
I'll put up a gist to show what I am thinking (and I need to try this hands-on for a bit to better understand this myself).
👍