cogentcore / core

A free and open source framework for building powerful, fast, and elegant 2D and 3D apps that run on macOS, Windows, Linux, iOS, Android, and the Web with a single pure Go codebase, allowing you to Code Once, Run Everywhere.
http://cogentcore.org/core
BSD 3-Clause "New" or "Revised" License
1.31k stars 71 forks source link

texteditor/layout.go use hash codes to optimize render updates #958

Open rcoreilly opened 1 month ago

rcoreilly commented 1 month ago

Describe the feature

a new LayoutAllLines call is made every time a new text line is added, and with any markup changes. most of the lines do not change, so we could usefully cache the existing renders. almost implemented it but an effective impl requires tracking the line insertion and deletion for the renders and hashes, which we are not currently doing (only buffer is doing it).

pass an update bool flag to LayoutAllLines and call with true from RenderLayout which is where all of these updates originate.

hash function returns uint64 https://pkg.go.dev/hash/maphash@go1.22.3#example-package

Relevant code

// hash code of text that was used to generate last Renders for each line.
    // used to optimize processing for Layout updates.
    renderHash []uint64