question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avoid creating new ArrayBuffers when reducing the size of the buffer

See original GitHub issue

See https://github.com/xtermjs/xterm.js/pull/4109#issuecomment-1243690016

I think we could actually change this:

https://github.com/xtermjs/xterm.js/blob/f9db65c52e4702cf906c14cda1c640342a7b6dca/src/common/buffer/BufferLine.ts#L335-L336

To:

this._data = this._data.subarray(0, cols * CELL_SIZE);

That will keep the same ArrayBuffer, but use a different view of it. We wouldn’t free the memory but maybe we should only do that either when the view is < 1/2 the size of the buffer, or defer the clean up to an idle timeout? It doesn’t make sense to do so many allocations if they’re being thrown away immediately after several resizes.

We could do something similar here:

https://github.com/xtermjs/xterm.js/blob/f9db65c52e4702cf906c14cda1c640342a7b6dca/src/common/buffer/BufferLine.ts#L347-L348

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
jerchcommented, Sep 13, 2022

Runtimes w’o zoomlevel madness:

  • shrinking ~85ms (~3x faster)
  • enlarging within bounds ~93ms (~2.7x faster)
  • enlarging out of bounds ~250ms (same speed)
1reaction
jerchcommented, Sep 13, 2022

Something weird is going on during enlarging in the demo. If I increase cols by one I get the following onResize dispatching:

image

Note that I changed cols to 87, which is correctly announce by the first onResize event, but gets reverted by a second event shrinking to 86. Therefore cols in the demo is off by one (stty size also reports 86 afterwards). For some reason the resize dispatching is messed up. It also explains why I see _reflowSmaller above in the profiler stats.

Edit: Oh well, this is a result of updateTerminalSize() in client.ts and FitAddon.fit not yielding the same numbers, if you have a zoom level on the browser (which I had by accident). With zoomlevel 100% I dont get the re-adjustment to cols-1 anymore. So the numbers above are flawed for enlarging (subtract the _reflowSmaller runtime). Not sure if this is worthing being fixed in client.ts, it might create frictions on integrator side, if they c&p the code? (created #4113).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resize ArrayBuffer - javascript - Stack Overflow
If I want to create an arraybuffer, I write: var buff = new ArrayBuffer(size). But how is it possible to resize an existing...
Read more >
Typed Arrays and ArrayBuffers / Jules Blom - Observable
An ArrayBuffer is an object representing a chunk of fixed-length binary data; ... Or use the static .from() method which creates a new...
Read more >
ArrayBuffer, binary arrays - The Modern JavaScript Tutorial
The basic binary object is ArrayBuffer – a reference to a fixed-length contiguous memory area. We create it like this: let buffer =...
Read more >
Resizable ArrayBuffer and growable SharedArrayBuffer - TC39
When the ArrayBuffer function is called with argument length and optional argument ... NOTE: Neither creation of the new Data Block nor copying...
Read more >
A cartoon intro to ArrayBuffers and SharedArrayBuffers
For example, when you create a variable in JS, the engine has to guess ... Except, when using an ArrayBuffer, you can't put...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found