perf: reduced pty bufferization window

This commit is contained in:
Eugene Pankov 2018-11-10 21:10:47 +01:00
parent 50ab4fc37e
commit 2e6acd2fa1

View File

@ -11,8 +11,11 @@ module.exports = function patchPTYModule (mod) {
let lastFlush = 0 let lastFlush = 0
let nextTimeout = 0 let nextTimeout = 0
const maxWindow = 250 // Minimum prebuffering window (ms) if the input is non-stop flowing
const minWindow = 50 const minWindow = 10
// Maximum buffering time (ms) until output must be flushed unconditionally
const maxWindow = 100
function flush () { function flush () {
if (buffer) { if (buffer) {
@ -36,9 +39,11 @@ module.exports = function patchPTYModule (mod) {
terminal.on('data', data => { terminal.on('data', data => {
buffer += data buffer += data
if (Date.now() - lastFlush > maxWindow) { if (Date.now() - lastFlush > maxWindow) {
// Taking too much time buffering, flush to keep things interactive
flush() flush()
} else { } else {
if (Date.now() > nextTimeout - (minWindow / 10)) { if (Date.now() > nextTimeout - (maxWindow / 10)) {
// Extend the window if it's expiring
reschedule() reschedule()
} }
} }