From 3ef43aedb114e0682ebdc2ea0fe1059ebd4fdda5 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 31 Jan 2026 10:26:15 -0800 Subject: [PATCH] Cache work cell in hot loops --- src/browser/OscLinkProvider.ts | 4 +++- src/common/buffer/BufferLine.ts | 7 +++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/browser/OscLinkProvider.ts b/src/browser/OscLinkProvider.ts index 18b0d2ba..b6a3cce0 100644 --- a/src/browser/OscLinkProvider.ts +++ b/src/browser/OscLinkProvider.ts @@ -9,6 +9,8 @@ import { CellData } from 'common/buffer/CellData'; import { IBufferService, IOptionsService, IOscLinkService } from 'common/services/Services'; export class OscLinkProvider implements ILinkProvider { + private readonly _workCell = new CellData(); + constructor( @IBufferService private readonly _bufferService: IBufferService, @IOptionsService private readonly _optionsService: IOptionsService, @@ -25,7 +27,7 @@ export class OscLinkProvider implements ILinkProvider { const result: ILink[] = []; const linkHandler = this._optionsService.rawOptions.linkHandler; - const cell = new CellData(); + const cell = this._workCell; const lineLength = line.getTrimmedLength(); let currentLinkId = -1; let currentStart = -1; diff --git a/src/common/buffer/BufferLine.ts b/src/common/buffer/BufferLine.ts index 03177076..e415851a 100644 --- a/src/common/buffer/BufferLine.ts +++ b/src/common/buffer/BufferLine.ts @@ -39,6 +39,7 @@ export const DEFAULT_ATTR_DATA = Object.freeze(new AttributeData()); // Work variables to avoid garbage collection let $startIndex = 0; +const $workCell = new CellData(); /** Factor when to cleanup underlying array buffer after shrinking. */ const CLEANUP_THRESHOLD = 2; @@ -262,9 +263,8 @@ export class BufferLine implements IBufferLine { } if (n < this.length - pos) { - const cell = new CellData(); for (let i = this.length - pos - n - 1; i >= 0; --i) { - this.setCell(pos + n + i, this.loadCell(pos + i, cell)); + this.setCell(pos + n + i, this.loadCell(pos + i, $workCell)); } for (let i = 0; i < n; ++i) { this.setCell(pos + i, fillCellData); @@ -284,9 +284,8 @@ export class BufferLine implements IBufferLine { public deleteCells(pos: number, n: number, fillCellData: ICellData): void { pos %= this.length; if (n < this.length - pos) { - const cell = new CellData(); for (let i = 0; i < this.length - pos - n; ++i) { - this.setCell(pos + i, this.loadCell(pos + n + i, cell)); + this.setCell(pos + i, this.loadCell(pos + n + i, $workCell)); } for (let i = this.length - n; i < this.length; ++i) { this.setCell(i, fillCellData);