Achieving low latency file i/o and string parsing

Summary:
I need advice on file i/o at bare minimum overhead (sub-millisecond to be more precise). (App design suggestion/crates/ -- What kind of file I should use? Any crates for this? etc)

I know this question is opinion-based but I want to hear good opinions.

Background:
Part of my project requires me to have a persistent stop-watch. Thinking of different approaches of creating a persistent stopwatch. What I'm thinking is, whenever a user starts a stopwatch:

  1. App creates a file somewhere in $HOME
  2. Whenever there's a "lap", that time will be written in that file in a new line
    This way, even if the app crashes or system shuts down, the stopwatch will keep "running". When the user comes back to the computer and runs the app and opens the stopwatch window, he'll see that the stop watch is still running, as the window keeps calculating the time difference in each millisecond.
  3. When the user presses the reset button, the app will remove that stopwatch file

Thus you achieve truly persistent stopwatch.

As you can see, I have to read a file and parse the strings within a very low time. Is there any better approach for keeping track of time instances?

You could store the time when the stopwatch starts and call elapsed when you want to display.

1 Like

I would look into something like redis. Redis will handle disk persistence for you.