Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send 'sub-frames' rather than the whole DOM
Firstly, this improves performance on a larger pages. But it also prevents browser crashes a very large pages by setting a limit to how much work is done per frame. Also includes: * Thread safe cell map for simultaneously reading and writing to the buffered frame of TTY cells. * Improved webext tests so that they programmaticlly build DOM rects based off simple text strings.
- Loading branch information
Showing
19 changed files
with
1,175 additions
and
438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package browsh | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/gdamore/tcell" | ||
) | ||
|
||
// A cell represents an individual TTY cell. An entire representation of the browser | ||
// DOM is stored in a local in-memory "frame". The TTY can then quickly render a region | ||
// of this frame for fast scrolling. | ||
type cell struct { | ||
character []rune | ||
fgColour tcell.Color | ||
bgColour tcell.Color | ||
} | ||
|
||
// Both updating a frame and scrolling a frame can happen at the same time, so we need | ||
// to use mutexes. | ||
type threadSafeCellsMap struct { | ||
sync.RWMutex | ||
internal map[int]cell | ||
} | ||
|
||
func newCellsMap() *threadSafeCellsMap { | ||
return &threadSafeCellsMap{ | ||
internal: make(map[int]cell), | ||
} | ||
} | ||
|
||
func (m *threadSafeCellsMap) load(key int) (value cell, ok bool) { | ||
m.RLock() | ||
result, ok := m.internal[key] | ||
m.RUnlock() | ||
return result, ok | ||
} | ||
|
||
func (m *threadSafeCellsMap) store(key int, value cell) { | ||
m.Lock() | ||
m.internal[key] = value | ||
m.Unlock() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.