Skip to content

Commit 632da79

Browse files
committed
Use borrows for the buffer when flagging a dirty line gives us
a 4.1% throughput improvement in the
1 parent 62ca111 commit 632da79

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

Sources/SwiftTerm/Terminal.swift

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ open class Terminal {
10081008
let buffer = self.buffer
10091009
readingBuffer.prepare(data)
10101010

1011-
updateRange (buffer.y)
1011+
updateRange(borrowing: buffer, buffer.y)
10121012
while readingBuffer.hasNext() {
10131013
var ch: Character = " "
10141014
var chWidth: Int = 0
@@ -1165,7 +1165,7 @@ open class Terminal {
11651165
}
11661166
}
11671167
existingLine [lastx] = cd
1168-
updateRange (last.y)
1168+
updateRange(borrowing: buffer, last.y)
11691169
continue
11701170
}
11711171
}
@@ -1183,7 +1183,7 @@ open class Terminal {
11831183
let charData = makeCharData (attribute: curAttr, char: ch, size: Int8 (chWidth))
11841184
buffer.insertCharacter(charData)
11851185
}
1186-
updateRange (buffer.y)
1186+
updateRange(borrowing: buffer, buffer.y)
11871187
readingBuffer.done ()
11881188
}
11891189

@@ -4605,7 +4605,31 @@ open class Terminal {
46054605
}
46064606
}
46074607
}
4608-
4608+
4609+
func updateRange (borrowing buffer: borrowing Buffer, _ y: Int, scrolling: Bool = false)
4610+
{
4611+
if !scrolling {
4612+
let effectiveY = buffer._yDisp + y
4613+
if effectiveY >= 0 {
4614+
if effectiveY < scrollInvariantRefreshStart {
4615+
scrollInvariantRefreshStart = effectiveY
4616+
}
4617+
if effectiveY > scrollInvariantRefreshEnd {
4618+
scrollInvariantRefreshEnd = effectiveY
4619+
}
4620+
}
4621+
}
4622+
4623+
if y >= 0 {
4624+
if y < refreshStart {
4625+
refreshStart = y
4626+
}
4627+
if y > refreshEnd {
4628+
refreshEnd = y
4629+
}
4630+
}
4631+
}
4632+
46094633
func updateRange (startLine: Int, endLine: Int, scrolling: Bool = false)
46104634
{
46114635
updateRange (startLine, scrolling: scrolling)

Tests/SwiftTermTests/PerformanceTest.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ final class PerformaceTests {
7777
}
7878

7979
@Test func repeatBigBlob() {
80+
// This file is generated with:
81+
// vtebench:
82+
// target/release/vtebench --max-samples 1 -b benchmarks/medium_cells/
8083
guard let d = try? Data(contentsOf: URL(filePath: "/Users/miguel/cvs/vtebench/x")) else {
8184
print("Skipping test, we do not have the data")
8285
return

0 commit comments

Comments
 (0)