

Nibble Stew: Looking at the performance of Refterm
source link: https://nibblestew.blogspot.com/2021/07/looking-at-performance-of-refterm.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Monday, July 5, 2021
Looking at the performance of Refterm
Recently a known strong-opinion-holder Casey Muratori wrote a reference implementation for a new fast terminal renderer. The goal is (as far as I can tell) to implement the same functionality as existing terminals using a lot less resources. The code is here and according to the readme it supports, for example:
- All of Unicode, including combining characters and right-to-left text like Arabic
- Line wrapping
- Reflowing line wrapping on terminal resize
Code setup
The code is arranged in a very non-standard way. There are two main source files, one C and one C++ that are built with a BAT file. Those files first #define a bunch of stuff and then #include all other source code files (not header files, source files) directly. This is very old school and against pretty much any recommended best practice for C. This works will for single-person projects but is a big hurdle for any new contributors.
The build uses the /GS- /Gs999999set command line arguments, which disable security features. This seems ill-advised for a terminal application, whose main job is to parse untrusted input. All libraries used are not defined in the build file but instead as pragmas inside the source files. The program also does not link the C library and because of this has its own simple implementations of memcpy and memset. This means you don't get the SIMD-optimized versions from the stdlib (the performance impact of this was not tested).
Resource usage
Resource consumption was measured by checking out the code, building it with the bat as instructed by upstream, starting the program and letting it idle. This is how it appears in Windows' task manager.
The app uses 0.5% of CPU and a whopping 14% of GPU just to display a blinking cursor. This could be said to be not particularly resource efficient. This is probably due to the fact that there is no rate limiter (or VSYNC) so the app just spams the system all the time. The true resource usage can't be meaningfully compared until this is fixed.
What can be measured, though, is memory usage. As can be seen in the image [1] the Refterm application uses 351 MB of memory when idle (the test war run using a 4k monitor). Based on discussions on the Internet, an acceptable amount of memory usage for a terminal is around 10-20 MB. Refterm uses 10x as much. In fact, as you can tell, running two instances of Refterm takes more memory than a fully blown Firefox with tens of open tabs. For comparison I also tested the Spotify app which is implemented in Electron. When playing music it only took ~150 MB, less than half of an idling Refterm.
Reliability
Conclusions
[1] I don't know much about Windows development, so I don't know how representative this number is of the "real" resource usage. At least on Linux the output of top should be taken with a grain of salt. I also tried VS's profiler and it claimed that the app took over 450 MB of ram.
Recommend
-
6
Nibble Stew A gathering of development thoughts of Jussi Pakkanen. Some of you may know him as the creator of the Meson build...
-
10
Millennium prize problems but for LinuxWednesday, February 24, 2021 Millennium prize problems but for Linux There is a longstanding tradition in mathematics to create a list of hard unsolved pro...
-
12
Microsoft is shipping a product built with Meson Some time ago Microsoft announced a compatibility pack to get OpenGL and OpenCL running even on computers whose hardware does not provide native OpenGL drivers. It is basically Ope...
-
14
Monday, February 1, 2021 Using a gamepad to control a painting application One of the hardest things in drawing and painting is controlling the individual strokes. Not only...
-
10
Never use environment variables for configurationWednesday, March 31, 2021 Never use environment variables for configuration Suppose you need to create a function for adding two numbers together...
-
8
Nibble Stew A gathering of development thoughts of Jussi Pakkanen. Some of you may know him as the creator of the Meson build...
-
17
Nibble Stew A gathering of development thoughts of Jussi Pakkanen. Some of you may know him as the creator of the Meson build...
-
6
After the first post, some more time was spent on building O3DE with Meson. This is the second and most likely last post on the subject. Currently
-
5
Nibble Stew A gathering of development thoughts of Jussi Pakkan...
-
10
Nibble Stew A gathering of development thoughts of Jussi Pakkan...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK