lichess-org/lila-ws

Not sure if frameLag calc is ideal

isaacl opened this issue · 2 comments

frameLag is currently a weighted running avg from trusted pongs.

This is very reasonable but what happens if a user hits a massive spike? The weighted avg skyrockets and won't return for a while. This translates into the old quota gain behavior for multiple moves in a row.

Consider:

  • capping millis so it can't skyrocket the frameLag weighted avg
  • changing the formula to drop faster if recording values that are lower than the current weighted avg.

For example:

private val trustedSpikeRefreshFactor = 0.05f
private val trustedNormalRefreshFactor = 0.1f
private val maxMillis = 5000
...

.fold(millis) { prev => {
    val weight = if (millis < prev) trustedNormalRefreshFactor else trustedSpikeRefreshFactor
    val cappedMillis = millis atMost maxMillis
    (prev * (1 - weight) + cappedMillis * weight).toInt
}
}

@ornicar @niklasf

(or something of this nature, potentially an even higher weight for low frameLag recordings)

I'll do some digging and follow up w a PR