telemetry-ios icon indicating copy to clipboard operation
telemetry-ios copied to clipboard

Move all disk I/O off-main

Open garvankeeley opened this issue 7 years ago • 2 comments

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.

garvankeeley avatar Oct 04 '17 20:10 garvankeeley

@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).

garvankeeley avatar Oct 13 '17 19:10 garvankeeley

👍

justindarc avatar Oct 13 '17 19:10 justindarc