Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove delegate allocation in jitter calculation in FramedClock #6122

Merged
merged 3 commits into from
Jan 11, 2024

Conversation

peppy
Copy link
Member

@peppy peppy commented Jan 10, 2024

Before After
2024-01-11 05 33 07@2x 2024-01-11 05 40 58@2x

}

double avg = sum / betweenFrameTimes.Length;
double variance = (sumOfSquares / betweenFrameTimes.Length) - (avg * avg);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am shook that this can be done and be actually correct.

Proof:

$$ \begin{align} \sigma_x &= \frac{\sum_i (x_i - \bar{x})^2}{|x|} = \\ &= \frac{\sum_i (x_i^2 - 2x_i \bar{x} + \bar{x}^2)}{|x|} = \\ &= \frac{\sum_i x_i^2}{|x|} - 2 \bar{x} \frac{\sum_i x_i}{|x|} + \bar{x}^2 \cdot \frac{\sum_i 1}{|x|} = \\ &= \frac{\sum_i x_i^2}{|x|} - 2 \bar{x} \cdot \bar{x} + \bar{x}^2 \cdot \frac{|x|}{|x|} = \\ &= \frac{\sum_i x_i^2}{|x|} - \bar{x}^2 \end{align} $$

wherein $x_i$ are elements of a set, $\bar{x}$ is the mean of the set, and $|x|$ is the cardinality of the set.

I thought there was no way this was gonna work but kept failing to find counterexamples...

@bdach bdach enabled auto-merge January 11, 2024 17:25
@bdach bdach merged commit 8346f6c into ppy:master Jan 11, 2024
13 checks passed
@peppy peppy deleted the frame-calc-delegate-overhead branch January 17, 2024 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants