-
-
Notifications
You must be signed in to change notification settings - Fork 783
Revise and optimize icons handling #1432
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
Conversation
This pretty much reworks the entire icon system. Some notable changes: * The extensions are put into a statically generated hash-table instead of a sorted array. We use Robin-Hood insertion to reduce the max probe length. Currently we need to probe only 2 slots for `O_EMOJI` and only 3 for `O_NERD`/`O_ICONS`. * I've opted not to use a perfect-hash since the perfect hashes generated by [`gperf`](https://www.gnu.org/software/gperf) used some huge lookup table. The hash function also wasn't as minimal as I'd like. * Colors are now using X-Macros. This should speed up startup since we don't have to search `icons_ext` linearly to find unique colors. * The hash-table generator outputs a more space optimized `struct icon_pair` using a char array instead of char pointer. This brings down the binary size from `145KiB` when using `O_NERD` down to `137KiB`. * Some unnecessary duplication and indirection has been reduced by using the `ICON_STR()` macro.
|
Simply awesome!!! 👍 |
|
@N-R-K Can you please update the ToDo list? |
|
If I try to bypass musl-gcc -march=native -O3 -DNORL -DNOLC -DNOMOUSE -DNOBATCH -DTOURBIN_QSORT -DNOSSN -DNOUG -DNOX11 -DEMOJI -std=c11 -Wall -Wextra -Wshadow -I../netbsd-curses/libcurses -I../musl-fts -o nnn src/nnn.c -Wl,-Bsymbolic-functions -lpthread -L/opt/nnn-libs -lcurses -lterminfo -lfts -static
src/nnn.c:128:10: fatal error: icons-generated.h: No such file or directory
128 | #include "icons-generated.h"
| ^~~~~~~~~~~~~~~~~~~
compilation terminated.What should I use instead of |
|
The following works: make O_EMOJI=1
musl-gcc -march=native -O3 -DNORL -DNOLC -DNOMOUSE -DNOBATCH -DTOURBIN_QSORT -DNOSSN -DNOUG -DNOX11 -DEMOJI -std=c11 -Wall -Wextra -Wshadow -I../netbsd-curses/libcurses -I../musl-fts -o nnn src/nnn.c -Wl,-Bsymbolic-functions -lpthread -L/opt/nnn-libs -lcurses -lterminfo -lfts |
First the "generator" needs to be built: $ gcc -DICONS_GENERATE -DEMOJI -o src/icons-hash-gen src/icons-hash.cThen the hash-table needs to be generated with the generator: $ ./src/icons-hash-gen > src/icons-generated.hNow you should be able to run the compile command manually as long as both the generator and The makefile already takes care of this. So just doing |
|
Settled with: CC=musl-gcc make O_EMOJI=1 src/icons-generated.h
musl-gcc -march=native -O3 -DNORL -DNOLC -DNOMOUSE -DNOBATCH -DTOURBIN_QSORT -DNOSSN -DNOUG -DNOX11 -DEMOJI -std=c11 -Wall -Wextra -Wshadow -I../netbsd-curses/libcurses -I../musl-fts -o nnn src/nnn.c -Wl,-Bsymbolic-functions -lpthread -L/opt/nnn-libs -lcurses -lterminfo -lfts -staticThank you! |
|
Updated the performance section on the wiki :) Also note that I still see some room for improvements. For example a lot of the extensions use the same icon. So instead of wasting 4 bytes (for There's also the possibility of using a minimal-perfect-hash, which can reduce memory usage by shrinking the table size but might make the hash-function/lookup slower. I still have lot more to learn and research on this topic. I'll see if I can make some time next weekend to implement and benchmark some of these ideas. If they turn out to be overall improvement, then I'll open the PR. |
|
Thank you! Keep it up! |
|
With the above options and musl-gcc, dynamically linked binary size: Static: Great improvement! |
This pretty much reworks the entire icon system. Some notable changes:
of a sorted array. We use Robin-Hood insertion to reduce the max probe
length. Currently we need to probe only 2 slots for
O_EMOJIand only3 for
O_NERD/O_ICONS.generated by
gperfused somehuge lookup table. The hash function also wasn't as minimal as I'd
like.
don't have to search
icons_extlinearly to find unique colors.struct icon_pairusing a char array instead of char pointer. This bringsdown the binary size from
145KiBwhen usingO_NERDdown to137KiB.the
ICON_STR()macro.