+
Skip to content

Microoptimise SetContent #771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Bios-Marcel
Copy link
Contributor

@Bios-Marcel Bios-Marcel commented Jan 18, 2025

  • Remove reflect.DeepEqual call in SetContent

    There's no need for reflection as we know the types.
    Given tcell wants to stay compatible with older go versions, we now have
    a small function that handles this, instead of using something like
    slices.Equal.

  • Add Simple benchmark to compare against the old versions
  • Reuse currComb and lastComb slices to prevent allocations
  • Optimise SetDirty calls in SetContent, don't re-lookup first cell

    This should be an improvent for ascii only rendering at least

Benchmark results:

D:\code\tcell> go test "-bench=." "-benchtime=10s" .
goos: windows
goarch: amd64
pkg: github.com/gdamore/tcell/v2
cpu: AMD Ryzen 7 9700X 8-Core Processor
Benchmark_SetContentOld_ascii-20           30164            374503 ns/op              74 B/op          0 allocs/op
Benchmark_SetContent_ascii-20              32296            409036 ns/op              69 B/op          0 allocs/op
Benchmark_SetContentOld-20                 19113            615607 ns/op           80119 B/op      10000 allocs/op
Benchmark_SetContent-20                    23109            492965 ns/op             100 B/op          0 allocs/op
PASS
ok      github.com/gdamore/tcell/v2     55.717s

@Bios-Marcel Bios-Marcel force-pushed the optimise_set_content branch 2 times, most recently from e47aeab to 4ab7a00 Compare January 18, 2025 13:00
* Remove reflect.DeepEqual call in SetContent
  > There's no need for reflection as we know the types.
  > Given tcell wants to stay compatible with older go versions, we now have
  > a small function that handles this, instead of using something like
  > `slices.Equal`.
* Add Simple benchmark to compare against the old versions
* Reuse `currComb` and `lastComb` slices to prevent allocations
* Optimise `SetDirty` calls in `SetContent`, rdDon't re-lookup first cell
  > This should be an improvent for ascii only rendering at least
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载