mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 07:18:17 +00:00
out_data_decide_throttle(): timeout instead of hard limit.
Instead of managing max_visits, check the time every N visits. This avoids edge cases where max_visits is large but the chunk frequency slowed down, which would causing the "..." pulse to show for a very long time. It's more important to show output at reasonable intervals than to avoid calling os_hrtime().
This commit is contained in:
@@ -26,7 +26,7 @@
|
|||||||
#include "nvim/strings.h"
|
#include "nvim/strings.h"
|
||||||
|
|
||||||
#define DYNAMIC_BUFFER_INIT { NULL, 0, 0 }
|
#define DYNAMIC_BUFFER_INIT { NULL, 0, 0 }
|
||||||
#define NS_1_SECOND 1000000000 // 1 second, in nanoseconds
|
#define NS_1_SECOND 1000000000U // 1 second, in nanoseconds
|
||||||
#define OUT_DATA_THRESHOLD 1024 * 10U // 10KB, "a few screenfuls" of data.
|
#define OUT_DATA_THRESHOLD 1024 * 10U // 10KB, "a few screenfuls" of data.
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -344,13 +344,11 @@ static bool out_data_decide_throttle(size_t size)
|
|||||||
static uint64_t started = 0; // Start time of the current throttle.
|
static uint64_t started = 0; // Start time of the current throttle.
|
||||||
static size_t received = 0; // Bytes observed since last throttle.
|
static size_t received = 0; // Bytes observed since last throttle.
|
||||||
static size_t visit = 0; // "Pulse" count of the current throttle.
|
static size_t visit = 0; // "Pulse" count of the current throttle.
|
||||||
static size_t max_visits = 0;
|
|
||||||
static char pulse_msg[] = { ' ', ' ', ' ', '\0' };
|
static char pulse_msg[] = { ' ', ' ', ' ', '\0' };
|
||||||
|
|
||||||
if (!size) {
|
if (!size) {
|
||||||
bool previous_decision = (visit > 0);
|
bool previous_decision = (visit > 0);
|
||||||
started = received = visit = 0;
|
started = received = visit = 0;
|
||||||
max_visits = 20;
|
|
||||||
return previous_decision;
|
return previous_decision;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,17 +359,9 @@ static bool out_data_decide_throttle(size_t size)
|
|||||||
return false;
|
return false;
|
||||||
} else if (!visit) {
|
} else if (!visit) {
|
||||||
started = os_hrtime();
|
started = os_hrtime();
|
||||||
} else if (visit >= max_visits && size < 256 && max_visits < 999) {
|
} else if (visit % 20 == 0) {
|
||||||
// Gobble up small chunks even if we maxed out. Avoids the case where the
|
|
||||||
// final displayed chunk is very tiny.
|
|
||||||
max_visits = visit + 1;
|
|
||||||
} else if (visit >= max_visits) {
|
|
||||||
uint64_t since = os_hrtime() - started;
|
uint64_t since = os_hrtime() - started;
|
||||||
if (since < NS_1_SECOND) {
|
if (since > (3 * NS_1_SECOND)) {
|
||||||
// Adjust max_visits based on the current relative performance.
|
|
||||||
// Each "pulse" period should last >=1 second so that it is perceptible.
|
|
||||||
max_visits = (2 * max_visits);
|
|
||||||
} else {
|
|
||||||
received = visit = 0;
|
received = visit = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -379,7 +369,7 @@ static bool out_data_decide_throttle(size_t size)
|
|||||||
|
|
||||||
visit++;
|
visit++;
|
||||||
// Pulse "..." at the bottom of the screen.
|
// Pulse "..." at the bottom of the screen.
|
||||||
size_t tick = (visit == max_visits)
|
size_t tick = (visit % 20 == 0)
|
||||||
? 3 // Force all dots "..." on last visit.
|
? 3 // Force all dots "..." on last visit.
|
||||||
: (visit % 4);
|
: (visit % 4);
|
||||||
pulse_msg[0] = (tick == 0) ? ' ' : '.';
|
pulse_msg[0] = (tick == 0) ? ' ' : '.';
|
||||||
|
Reference in New Issue
Block a user