Skip to content
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

Microoptimise SetContent #771

Open
wants to merge 1 commit 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-16          108651            109888 ns/op
Benchmark_SetContent_ascii-16             116324            103552 ns/op
Benchmark_SetContentOld-16                 37220            323573 ns/op
Benchmark_SetContent-16                    55806            215194 ns/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