Skip to content

Commit b9b42ef

Browse files
authored
Merge pull request #3452 from Tyriar/perf_fixes
Throughput performance improvements
2 parents 77461a3 + 20460a2 commit b9b42ef

File tree

3 files changed

+224
-238
lines changed

3 files changed

+224
-238
lines changed

src/browser/Viewport.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { addDisposableDomListener } from 'browser/Lifecycle';
88
import { IColorSet, IViewport } from 'browser/Types';
99
import { ICharSizeService, IRenderService } from 'browser/services/Services';
1010
import { IBufferService, IOptionsService } from 'common/services/Services';
11+
import { IBuffer } from 'common/buffer/Types';
12+
import { IRenderDimensions } from 'browser/renderer/Types';
1113

1214
const FALLBACK_SCROLL_BAR_WIDTH = 15;
1315

@@ -18,12 +20,15 @@ const FALLBACK_SCROLL_BAR_WIDTH = 15;
1820
export class Viewport extends Disposable implements IViewport {
1921
public scrollBarWidth: number = 0;
2022
private _currentRowHeight: number = 0;
23+
private _currentScaledCellHeight: number = 0;
2124
private _lastRecordedBufferLength: number = 0;
2225
private _lastRecordedViewportHeight: number = 0;
2326
private _lastRecordedBufferHeight: number = 0;
2427
private _lastTouchY: number = 0;
2528
private _lastScrollTop: number = 0;
2629
private _lastHadScrollBar: boolean = false;
30+
private _activeBuffer: IBuffer;
31+
private _renderDimensions: IRenderDimensions;
2732

2833
// Stores a partial line amount when scrolling, this is used to keep track of how much of a line
2934
// is scrolled so we can "scroll" over partial lines and feel natural on touchpads. This is a
@@ -51,6 +56,12 @@ export class Viewport extends Disposable implements IViewport {
5156
this._lastHadScrollBar = true;
5257
this.register(addDisposableDomListener(this._viewportElement, 'scroll', this._onScroll.bind(this)));
5358

59+
// Track properties used in performance critical code manually to avoid using slow getters
60+
this._activeBuffer = this._bufferService.buffer;
61+
this.register(this._bufferService.buffers.onBufferActivate(e => this._activeBuffer = e.activeBuffer));
62+
this._renderDimensions = this._renderService.dimensions;
63+
this.register(this._renderService.onDimensionsChange(e => this._renderDimensions = e));
64+
5465
// Perform this async to ensure the ICharSizeService is ready.
5566
setTimeout(() => this.syncScrollArea(), 0);
5667
}
@@ -79,6 +90,7 @@ export class Viewport extends Disposable implements IViewport {
7990
private _innerRefresh(): void {
8091
if (this._charSizeService.height > 0) {
8192
this._currentRowHeight = this._renderService.dimensions.scaledCellHeight / window.devicePixelRatio;
93+
this._currentScaledCellHeight = this._renderService.dimensions.scaledCellHeight;
8294
this._lastRecordedViewportHeight = this._viewportElement.offsetHeight;
8395
const newBufferHeight = Math.round(this._currentRowHeight * this._lastRecordedBufferLength) + (this._lastRecordedViewportHeight - this._renderService.dimensions.canvasHeight);
8496
if (this._lastRecordedBufferHeight !== newBufferHeight) {
@@ -126,20 +138,13 @@ export class Viewport extends Disposable implements IViewport {
126138
}
127139

128140
// If the buffer position doesn't match last scroll top
129-
const newScrollTop = this._bufferService.buffer.ydisp * this._currentRowHeight;
130-
if (this._lastScrollTop !== newScrollTop) {
131-
this._refresh(immediate);
132-
return;
133-
}
134-
135-
// If element's scroll top changed, this can happen when hiding the element
136-
if (this._lastScrollTop !== this._viewportElement.scrollTop) {
141+
if (this._lastScrollTop !== this._activeBuffer.ydisp * this._currentRowHeight) {
137142
this._refresh(immediate);
138143
return;
139144
}
140145

141146
// If row height changed
142-
if (this._renderService.dimensions.scaledCellHeight / window.devicePixelRatio !== this._currentRowHeight) {
147+
if (this._renderDimensions.scaledCellHeight !== this._currentScaledCellHeight) {
143148
this._refresh(immediate);
144149
return;
145150
}

0 commit comments

Comments
 (0)