Skip to content
This repository was archived by the owner on Aug 4, 2024. It is now read-only.

Commit 833fa71

Browse files
author
Ookiineko
committed
web-shims: only update UI on new line
- magiskboot doesn't stop at the middle of a line so there were not actually needed this should improve terminal perf by a little Signed-off-by: Ookiineko <chiisaineko@protonmail.com>
1 parent 70dfa34 commit 833fa71

1 file changed

Lines changed: 6 additions & 25 deletions

File tree

src/web-shims/conio_hack.cc

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
/* 20 ms */
1111
#define MBB_CONIO_DELAY (20)
1212

13-
/* 10 characters */
14-
#define MBB_CONOUT_THRESHOLD (10)
15-
1613
// used for exit code callback in JS
1714

1815
extern int __mbb_main(int argc, char **argv);
@@ -95,7 +92,7 @@ extern "C" {
9592
}
9693
}
9794

98-
static void __exit_hook(int status) {
95+
static inline void __exit_hook(int status) {
9996
EM_ASM({
10097
Module['mbb_main_cb']($0);
10198
}, status);
@@ -117,28 +114,17 @@ __attribute__((noreturn)) static void __exit_wrap(int status) {
117114
__real_exit(status);
118115
}
119116

120-
static void __conout_hook(const char *s, size_t len) {
121-
// when should we update UI?
122-
123-
if (len >= MBB_CONOUT_THRESHOLD)
124-
goto do_sleep; // when the line is long enough
125-
126-
if (memchr(s, '\n', len) || memchr(s, '\r', len))
127-
goto do_sleep; // when there is a newline char in the str
117+
static inline void __conout_hook(const char *s, size_t len) {
118+
// give browser a chance to update UI on each new line
128119

129-
return;
130-
131-
do_sleep:
132-
// sleeping is even more expensive to perf
133-
// so only do this when needed
134-
emscripten_sleep(MBB_CONIO_DELAY); // note this needs -sASYNCIFY in LDFLAGS
120+
if (memchr(s, '\n', len))
121+
emscripten_sleep(MBB_CONIO_DELAY); // note this needs -sASYNCIFY in LDFLAGS
135122
}
136123

137-
static void __check_do_conout_hook(int fd, const char *s, size_t len) {
124+
static inline void __check_do_conout_hook(int fd, const char *s, size_t len) {
138125
switch (fd) {
139126
case STDOUT_FILENO:
140127
case STDERR_FILENO:
141-
// give browser a chance to update UI
142128
__conout_hook(s, len);
143129
break;
144130
default:
@@ -193,8 +179,3 @@ static void __enable_conio_hack(void) {
193179
EMSCRIPTEN_BINDINGS(conio_hack) {
194180
emscripten::function("mbb_enable_conio_hack", &__enable_conio_hack);
195181
}
196-
197-
__attribute__((constructor)) static void __init_io_mode(void) {
198-
// disable line buffering
199-
setvbuf(stdout, NULL, _IONBF, BUFSIZ);
200-
}

0 commit comments

Comments
 (0)