Skip to content

Adjust length of sleep instruction on TimerWorker for time spent refreshing#2236

Open
Raikzer wants to merge 4 commits into
LiveSplit:masterfrom
Raikzer:precise-refresh-rate
Open

Adjust length of sleep instruction on TimerWorker for time spent refreshing#2236
Raikzer wants to merge 4 commits into
LiveSplit:masterfrom
Raikzer:precise-refresh-rate

Conversation

@Raikzer
Copy link
Copy Markdown

@Raikzer Raikzer commented Mar 19, 2022

This will increase the consistency of the timer refresh rate when more resource intensive components are used (ie load removers using optical character recognition)

On a side note: Due to delay between a thread's sleep duration ending and the thread actually resuming execution the refresh rate entered in the settings will differ vastly from the refresh rate actually achieved (ie entering a refresh rate of 30 will result in an actual refresh rate of 23)

@wooferzfg wooferzfg added the enhancement Suggests or implements new or improved features. label Mar 19, 2022
@wooferzfg
Copy link
Copy Markdown
Member

entering a refresh rate of 30 will result in an actual refresh rate of 23

Is there a way to resolve this?

@goofball564
Copy link
Copy Markdown

goofball564 commented Apr 12, 2022

Sorry for the minor wall of text.

Re: Refresh Rate Inaccuracy

One solution to inaccurate refresh rates would be calls to timeBeginPeriod and timeEndPeriod. This affects a global Windows setting and comes with significantly increased power consumption, reduced battery life, and reduced system performance, since it means Windows's thread scheduler is awoken up to 15.625x more often than normal. Otherwise Windows's default system timer resolution of is 64 ticks/second, which limits the precision of Thread.Sleep to 15.625 milliseconds.

Re: DateTime.Now.Ticks

Wouldn't it be better to use a Stopwatch than DateTime.Now.Ticks? It's (probably) much more precise, and measuring elapsed time is what Stopwatch is meant for. DateTime.UtcNow.Ticks would at least be less expensive since it doesn't have to do time zone calculations. It's also Stopwatch's backup if QueryPerformanceCounter isn't available.

DateTime.UtcNow.Ticks and DateTime.Now.Ticks are affected by the system clock being changed and are limited in accuracy by Windows's system timer resolution. DateTime.Now could also maybe potentially risk time zone related bugs.

@thekovic
Copy link
Copy Markdown

This affects a global Windows setting and comes with significantly increased power consumption, reduced battery life, and reduced system performance, since it means Windows's thread scheduler is awoken up to 15.625x more often than normal.

That sounds awful. I'd never want LiveSplit to significantly affect system performance.

@Raikzer
Copy link
Copy Markdown
Author

Raikzer commented Apr 18, 2022

Stopwatch has the exact same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Suggests or implements new or improved features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants