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

Time-based limit for Terminal._innerWrite #4

Merged
merged 4 commits into from Jan 4, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,5 +1,5 @@
{
"name": "xterm",
"name": "@zeit/xterm",
"description": "Full xterm terminal, in your browser",
"version": "3.9.1",
"main": "lib/public/Terminal.js",
@@ -65,10 +65,12 @@ const document = (typeof window !== 'undefined') ? window.document : null;
const WRITE_BUFFER_PAUSE_THRESHOLD = 5;

/**
* The number of writes to perform in a single batch before allowing the
* renderer to catch up with a 0ms setTimeout.
* The max number of ms to spend on writes before allowing the renderer to
* catch up with a 0ms setTimeout. A value of < 33 to keep us close to
* 30fps, and a value of < 16 to try to run at 60fps. Of course, the real FPS
* depends on the time it takes for the renderer to draw the frame.
*/
const WRITE_BATCH_SIZE = 300;
const WRITE_TIMEOUT_MS = 12;

/**
* The set of options that only have an effect when set in the Terminal constructor.
@@ -1361,13 +1363,13 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
this.writeBuffer = [];
}

const writeBatch = this.writeBuffer.splice(0, WRITE_BATCH_SIZE);
while (writeBatch.length > 0) {
const data = writeBatch.shift();
const startTime = Date.now();
while (this.writeBuffer.length > 0) {
const data = this.writeBuffer.shift();

// If XOFF was sent in order to catch up with the pty process, resume it if
// the writeBuffer is empty to allow more data to come in.
if (this._xoffSentToCatchUp && writeBatch.length === 0 && this.writeBuffer.length === 0) {
if (this._xoffSentToCatchUp && this.writeBuffer.length === 0) {
this.handler(C0.DC1);
this._xoffSentToCatchUp = false;
}
@@ -1385,6 +1387,10 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II

this.updateRange(this.buffer.y);
this.refresh(this._refreshStart, this._refreshEnd);

if (Date.now() - startTime >= WRITE_TIMEOUT_MS) {
break;
}
}
if (this.writeBuffer.length > 0) {
// Allow renderer to catch up before processing the next batch
@@ -85,7 +85,7 @@ export default class WebglCharAtlas extends BaseCharAtlas {
this._tmpCtx = this._tmpCanvas.getContext('2d', {alpha: this._config.allowTransparency});

// This is useful for debugging
document.body.appendChild(this.cacheCanvas);
// document.body.appendChild(this.cacheCanvas);
}

public dispose(): void {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.