4 ms·
I'm a bit puzzled by "reducing binary footprint (surprisingly) by removing bloated dependencies" since linenoise has no dependencies (beyond libc) that I'm awar
by swetland 5y ago
I'm a bit puzzled by "reducing binary footprint (surprisingly) by removing bloated dependencies" since linenoise has no dependencies (beyond libc) that I'm aware of.
$ size linenoise_example
text data bss dec hex filename
14718 948 184 15850 3dea linenoise_example
$ size bestline_example
text data bss dec hex filename
40830 1000 9280 51110 c7a6 bestline_example
Which seems reasonable since bestline has a bunch of unicode tables and handling for a bunch of editing features beyond linenoise's minimalist featureset, but I still don't understand the "bloated dependencies" remark...
- masklinn 5y agoThe readme mentions > Remove heavyweight dependencies like printf/sprintf But that’s from libc, unless they measure by statically linking everything?
- _ph_ 5y agoWhen you think about using the library from languages which don't link against libc by default (Go for example), then this is a significant difference.
- masklinn 5y agoHow does Go have any relevance? This is a C program, it will link against libc.
- R0b0t1 5y agoThe example is still relevant, say if your program has no OS.
- masklinn 5y ago> The example is still relevant, say if your program has no OS. Not only does it seem unlikely your program would have a terminal output and standard streams without having an OS, bestline still requires a libc. Just open `bestline.c` and you'll find: #include <termios.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <unistd.h> #include <setjmp.h> #include <poll.h> #include <assert.h> #include <signal.h> #include <fcntl.h> #include <limits.h>
- R0b0t1 5y agoYou've never used a microcontroller. They are usually shipped with a partial libc that binds fd 0/1 to a USART. Sometimes POSIX threads can be mapped to FreeRTOS calls. Most of the defines can have a null implementation and the core will still work. They just need to be defined.
- masklinn 5y agoYou’re not making any sense. If the system provides a libc stub then printf and whatever are not concerns, they’ll just go through the stub. And the message I quoted says literally nothing about µc.
- _ph_ 5y agoYou can easily call C libraries from languages like Go and Rust. It absolutely makes sense to write small libraries in C so that all kind of languages can use the library which are not C. Go programs by default do not link against libc, so it would be nice not introducing the dependency. So this would fall under "nice to have".
- drran 5y agoWhy I need to use readline on a system without libc, e.g. a heavily optimized container?
- masklinn 5y agoBestline does not work without a libc, you can just open the main c file and see that it’s full of libc #includes.
- jart 5y agoAuthor here. It's a question of beneath the iceberg dependencies revealed by static linking. $ make clean && CC="x86_64-linux-musl-gcc -s -static -DNDEBUG -Os" make $ ls -hal bestline_example -rwxr-xr-x 1 jart jart 38K Sep 19 21:41 bestline_example Linenoise grows considerably when statically linked, since it needs functions like printf/scanf, which add footprint without adding a whole lot of value to the library. $ make clean && CC="x86_64-linux-musl-gcc -s -static -DNDEBUG -Os" make $ ls -hal linenoise_example -rwxr-xr-x 1 jart jart 50K Sep 19 21:41 linenoise_example Bestline refactors the Linenoise code so the linker won't pull printf functions into the linkage. That freed up about 30kb of space, which was then used to provide UNICODE and near-feature parity with GNU Readline. It matters because a library that's this low-level and so fundamental to the needs of nearly every program, should impose as few choices upon the user as possible, in terms of what other things they're required to support. For example, many people don't like printf() style interfaces and therefore do not want them included in their address space. The same goes for huge libraries like Curses and ICU that require you to link in megs of code/data just to read a character correctly. You want the value those things offer, but you don't want the baggage if all you care about is just reading a line comfortably. That's where Bestline comes in. It distills the value of all those heavyweight dependencies down into a single .c file focused on reading lines and only reading lines, which everyone can agree on, that's actually tinier than the original library at the end of the day. So you get a better value as a software developer in terms of the code complexity and dependency bloat you need to take on.