linebender / linebender/druid

Timestamp in events

Open
#476 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

architecture
Dominant language
Rust
Stars
9.7k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

Events don't have a timestamp, but they should. The main reason they don't yet is that it's a tricky problem to choose an appropriate type for the timestamp and convert timestamps from the system into it. Should this timestamp be comparable to [`std::time::Instant`](https://doc.rust-lang.org/std/time/struct.Instant.html)?

On Windows, there is a `time` field in the [`MSG`](https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-msg) struct. This is helpfully documented as "The time at which the message was posted." Based on a [Raymond Chen blog](https://devblogs.microsoft.com/oldnewthing/20140122-00/?p=2013), I believe this is 32 bit time in milliseconds as returned by [GetTickCount](https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-gettickcount), and also with very poor resolution guarantees (in other words, it may or may not be a lower quality time source than calling `Instant::now()` in the window message handler). The 32 bitness is also a problem, it will overflow in a couple of months.

On macOS, it's [NSEvent.timestamp](https://developer.apple.com/documentation/appkit/nsevent/1528239-timestamp?language=objc), which is an interval since system startup, as a 64 bit float. Again, this cannot be compared to an `Instant::now()`, for example to measure the delay between when the event was created and when it was processed.

I haven't investigated Linux/Gtk.

The timestamp of the event is related to other relevant timestamps in the system, including sound and audio. Synchronization is a *very* tricky problem. It's probably out of scope to try to fully solve it now, but we should keep it in mind so we don't paint ourselves into a corner. One highly relevant source of timestamps is frame presentation statistics, for example [DXGI_FRAME_STATISTICS](https://docs.microsoft.com/en-us/windows/win32/api/dxgi/ns-dxgi-dxgi_frame_statistics) on Windows. Ideally, these should also be used instead of the current time for generating animation intervals.

There are many open questions. Should we have both a "posted" and "retrieved" timestamp? Should we be trying to do sophisticated heuristics (something roughly like a clawback filter) to synchronize the various disparate sources of timestamp data? Discussion is welcome, and this might be a good issue for someone who loves a deep challenge.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's platform references for Windows MSG.time, macOS NSEvent.timestamp, and the uninvestigated Linux/Gtk path. Resolve the open questions about timestamp type, posted versus retrieved times, cross-platform conversion, and synchronization with related system timestamps. Done requires an agreed design rather than a single obvious edit.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
desktop, operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.