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

chore: optimize memory usage of tcell library on init #7579

Merged
merged 1 commit into from
Aug 4, 2023

Conversation

smira
Copy link
Member

@smira smira commented Aug 4, 2023

There are two changes here:

  • build machined binary with tcell_minimal tag (which disables loading some parts of the terminfo database), which also affects apid, trustd and dashboard processes, as they run from the same executable; in dashboard explicitly import linux terminal we're using when the dashboard runs on the machine
  • pass TCELL_MINIMIZE=1 environment variable to each Talos process which removes 0.5MiB of runewdith allocation for a lookup table

See #7578

There are two changes here:

* build `machined` binary with `tcell_minimal` tag (which disables
  loading some parts of the terminfo database), which also affects
  `apid`, `trustd` and `dashboard` processes, as they run from the same
  executable; in `dashboard` explicitly import `linux` terminal we're
  using when the `dashboard` runs on the machine
* pass `TCELL_MINIMIZE=1` environment variable to each Talos process
  which removes 0.5MiB of runewdith allocation for a lookup table

See siderolabs#7578

Signed-off-by: Andrey Smirnov <[email protected]>
@smira smira added this to the v1.6 milestone Aug 4, 2023
@smira
Copy link
Member Author

smira commented Aug 4, 2023

Final allocs on init:

init github.com/gdamore/tcell/v2/terminfo @19 ms, 0 ms clock, 64 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/a/ansi @19 ms, 0.002 ms clock, 3280 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/v/vt100 @19 ms, 0.001 ms clock, 3088 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/v/vt102 @19 ms, 0 ms clock, 3072 bytes, 1 allocs
init github.com/gdamore/tcell/v2/terminfo/v/vt220 @19 ms, 0.001 ms clock, 3088 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/x/xterm @19 ms, 0.014 ms clock, 12944 bytes, 8 allocs
init github.com/gdamore/tcell/v2 @19 ms, 0.044 ms clock, 25584 bytes, 29 allocs
init github.com/gdamore/tcell/v2/terminfo/l/linux @19 ms, 0.004 ms clock, 3072 bytes, 1 allocs

with tcell_minimal build tag, but without TCELL_MINIMIZE=1:

init github.com/gdamore/tcell/v2/terminfo @17 ms, 0 ms clock, 64 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/a/ansi @17 ms, 0.004 ms clock, 3280 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/v/vt100 @17 ms, 0 ms clock, 3088 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/v/vt102 @17 ms, 0 ms clock, 3072 bytes, 1 allocs
init github.com/gdamore/tcell/v2/terminfo/v/vt220 @17 ms, 0.007 ms clock, 3088 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/x/xterm @17 ms, 0.008 ms clock, 12736 bytes, 7 allocs
init github.com/gdamore/tcell/v2 @17 ms, 21 ms clock, 582400 bytes, 28 allocs

with main branch:

init github.com/gdamore/tcell/v2/terminfo @15 ms, 0 ms clock, 64 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/a/aixterm @15 ms, 0.002 ms clock, 3280 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/a/alacritty @15 ms, 0.001 ms clock, 6144 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/a/ansi @15 ms, 0.001 ms clock, 3072 bytes, 1 allocs
init github.com/gdamore/tcell/v2/terminfo/b/beterm @15 ms, 0.001 ms clock, 3072 bytes, 1 allocs
init github.com/gdamore/tcell/v2/terminfo/c/cygwin @15 ms, 0.001 ms clock, 3072 bytes, 1 allocs
init github.com/gdamore/tcell/v2/terminfo/d/dtterm @15 ms, 0 ms clock, 3072 bytes, 1 allocs
init github.com/gdamore/tcell/v2/terminfo/e/emacs @15 ms, 0.002 ms clock, 6560 bytes, 3 allocs
init github.com/gdamore/tcell/v2/terminfo/f/foot @15 ms, 0.001 ms clock, 3088 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/g/gnome @15 ms, 0.005 ms clock, 6352 bytes, 3 allocs
init github.com/gdamore/tcell/v2/terminfo/h/hpterm @15 ms, 0.002 ms clock, 3984 bytes, 3 allocs
init github.com/gdamore/tcell/v2/terminfo/k/konsole @15 ms, 0.001 ms clock, 6144 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/k/kterm @15 ms, 0.001 ms clock, 3072 bytes, 1 allocs
init github.com/gdamore/tcell/v2/terminfo/l/linux @15 ms, 0.001 ms clock, 3072 bytes, 1 allocs
init github.com/gdamore/tcell/v2/terminfo/p/pcansi @15 ms, 0 ms clock, 3072 bytes, 1 allocs
init github.com/gdamore/tcell/v2/terminfo/r/rxvt @15 ms, 0.005 ms clock, 15360 bytes, 5 allocs
init github.com/gdamore/tcell/v2/terminfo/s/screen @15 ms, 0.002 ms clock, 7936 bytes, 3 allocs
init github.com/gdamore/tcell/v2/terminfo/s/simpleterm @15 ms, 0.001 ms clock, 6144 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/s/sun @15 ms, 0.003 ms clock, 6176 bytes, 3 allocs
init github.com/gdamore/tcell/v2/terminfo/t/termite @15 ms, 0 ms clock, 3072 bytes, 1 allocs
init github.com/gdamore/tcell/v2/terminfo/t/tmux @15 ms, 0.001 ms clock, 6144 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/v/vt100 @15 ms, 0.003 ms clock, 3088 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/v/vt102 @15 ms, 0 ms clock, 3072 bytes, 1 allocs
init github.com/gdamore/tcell/v2/terminfo/v/vt220 @15 ms, 0 ms clock, 3088 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/v/vt320 @15 ms, 0.007 ms clock, 3088 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/v/vt400 @15 ms, 0.001 ms clock, 3104 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/v/vt420 @15 ms, 0.001 ms clock, 3280 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/v/vt52 @15 ms, 0 ms clock, 3280 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/w/wy50 @15 ms, 0.001 ms clock, 3088 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/w/wy60 @15 ms, 0.001 ms clock, 3088 bytes, 2 allocs
init github.com/gdamore/tcell/v2/terminfo/w/wy99_ansi @15 ms, 0.003 ms clock, 10264 bytes, 4 allocs
init github.com/gdamore/tcell/v2/terminfo/x/xfce @15 ms, 0.001 ms clock, 3072 bytes, 1 allocs
init github.com/gdamore/tcell/v2/terminfo/x/xterm @15 ms, 0.004 ms clock, 12320 bytes, 6 allocs
init github.com/gdamore/tcell/v2/terminfo/x/xterm_kitty @15 ms, 0.001 ms clock, 3072 bytes, 1 allocs
init github.com/gdamore/tcell/v2/terminfo/x/xterm_termite @15 ms, 0.001 ms clock, 3072 bytes, 1 allocs
init github.com/gdamore/tcell/v2/terminfo/dynamic @15 ms, 0 ms clock, 16 bytes, 1 allocs
init github.com/gdamore/tcell/v2 @15 ms, 17 ms clock, 582968 bytes, 30 allocs

The code which deactivates with the env variable: https://github.com/gdamore/tcell/blob/47ec3a77754f83e84481fc9cdd0bc2072cd292ba/cell.go#L195-L201

Copy link
Member

@DmitriyMV DmitriyMV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆒

744912 bytes before. 54192 bytes after.

@smira
Copy link
Member Author

smira commented Aug 4, 2023

744912 bytes before. 54192 bytes after.

and also -21ms startup time (out of full 34ms).

@smira
Copy link
Member Author

smira commented Aug 4, 2023

/m

@talos-bot talos-bot merged commit fb536af into siderolabs:main Aug 4, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backported
Development

Successfully merging this pull request may close these issues.

4 participants