Skip to content

Commit 06570c8

Browse files
committed
[feat] improve performance while filtering
1 parent 19f8089 commit 06570c8

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

internal/model/page_log.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,28 @@ type PageLog struct {
3636
}
3737

3838
func (l PageLog) Render() linebuffer.LineBufferer {
39+
return l.render(true)
40+
}
41+
42+
func (l PageLog) RenderWithoutStyle() linebuffer.LineBufferer {
43+
return l.render(false)
44+
}
45+
46+
func (l PageLog) render(includeStyle bool) linebuffer.LineBufferer {
3947
ts := ""
4048
if l.CurrentTimestamp != "" {
41-
ts = l.Styles.Green.Render(l.CurrentTimestamp)
49+
if includeStyle {
50+
ts = l.Styles.Green.Render(l.CurrentTimestamp)
51+
} else {
52+
ts = l.CurrentTimestamp
53+
}
4254
}
4355
label := ""
4456
if l.CurrentName.ContainerName != "" {
4557
if ts != "" {
4658
label += " "
4759
}
48-
label += l.RenderName(*l.CurrentName, true)
60+
label += l.RenderName(*l.CurrentName, includeStyle)
4961
}
5062

5163
prefix := ts + label

internal/page/logs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func NewLogsPage(
4848
Height: height,
4949
AllRows: lc.GetOrderedLogs(),
5050
MatchesFilter: func(log model.PageLog, filter filter.Model) bool {
51-
return log.Render().Matches(filter)
51+
return log.RenderWithoutStyle().Matches(filter)
5252
},
5353
ViewWhenEmpty: "No logs yet",
5454
Styles: styles,

internal/viewport/linebuffer/linebuffer.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type LineBuffer struct {
1717
lineNoAnsiRuneWidths []uint8 // terminal cell widths
1818
ansiCodeIndexes [][]uint32 // slice of startByte, endByte indexes of ansi codes
1919
numNoAnsiRunes int // number of runes in lineNoAnsi
20+
totalWidth int // total width in terminal cells
2021

2122
sparsity int // interval for which to store cumulative cell width
2223
sparseRuneIdxToNoAnsiByteOffset []uint32 // rune idx to byte offset of lineNoAnsi, stored every sparsity runes
@@ -86,6 +87,9 @@ func New(line string) LineBuffer {
8687
lb.sparseRuneIdxToNoAnsiByteOffset[runeIdx/lb.sparsity] = currentOffset
8788
lb.sparseLineNoAnsiCumRuneWidths[runeIdx/lb.sparsity] = cumWidth
8889
}
90+
if runeIdx == numRunes-1 {
91+
lb.totalWidth = int(cumWidth)
92+
}
8993
currentOffset += uint32(runeNumBytes)
9094
runeIdx++
9195
byteOffset += runeNumBytes
@@ -99,8 +103,7 @@ func (l LineBuffer) Width() int {
99103
if len(l.line) == 0 {
100104
return 0
101105
}
102-
lastRuneIdx := len(l.lineNoAnsiRuneWidths) - 1
103-
return int(l.getCumulativeWidthAtRuneIdx(lastRuneIdx))
106+
return l.totalWidth
104107
}
105108

106109
func (l LineBuffer) Content() string {

0 commit comments

Comments
 (0)