Hacker News new | ask | show | jobs
by kragen 718 days ago
yeah, the chip-8 design is less ambitious than the uxn design and can only really handle very limited programs. on the other hand, it does run on much smaller hardware

i wouldn't go so far as to say uxn is flawed; that suggests it's fundamentally unsound. as far as i know, it isn't; it's a perfectly workable design, and it's better than anything else so far for frugal write-once-run-anywhere. i think a different design would be better in important ways, but vaporware is always better than actually implemented systems

> One of the motivating factors for 100r was that Xcode is bad fit for people who live on a boat with solar-powered computers. So are Visual Studio or PyCharm.

that's true, but you're damning uxn with faint praise here. i suspected that if you benchmarked left¹ (which, incidentally, does do syntax highlighting) against a default configuration of vim or gnu emacs, you'd find that left is the one that consumes the most power

but then i tried it, and also compared an extremely minimal editor called `ae`, and left seems to use a third as much power as emacs, but five times as much as vim and 300 times as much as ae

ae and left could plausibly run on the zorzpad. vim and emacs cannot; they need far too much ram. ae and left also have in common that they both lack undo, but left is dramatically more capable and easier to use

— emacs power usage —

i've been running my current emacs process for a week and (not counting cpu time used by the x server) it's used 34 minutes and 15 seconds of cpu, which is about 0.3% of one core of this amd ryzen 3500u. if we estimate that the cpu draws 29 more watts from the battery when running full-speed than when completely idle, and can run about 3 instructions per clock per core on each of 4 cores and 3.1 gigahertz working out to 36 billion instructions per second, emacs is consuming about 90 milliwatts and running about 100 million instructions per second on average

that's a lot higher than i expected, and possibly actually higher than left (i haven't tested) but it's certainly not in the same league as vscode. (this is emacs 28.2, and somewhat to my surprise, system-configuration-options tells me it's built --with-native-compilation, so perhaps it's not using the inefficient old bytecode interpreter.)

as a more precise test, to test emacs's built-in ide functionality rather than gtk and my proliferation of elisp packages, i ran `valgrind --tool=cachegrind emacs -q -nw --no-site-file` and wrote this c program in it:

    #include <stdio.h>

    int main(int argc, char **argv)
    {
      char buf[256];
      printf("What's your name? ");
      fflush(stdout);
      fgets(buf, sizeof buf, stdin);
      for (char *p = buf; *p; p++) if (*p == '\n') *p = '\0';
      printf("Oh, hi, %s!  Lovely to meet you!\n", buf);
      return 0;
    }
syntax highlighting was enabled, but -nw runs it in the terminal. i compiled it, fixed bugs in it (at first i didn't have any but i wanted to ensure i was doing a fair test), jumped to error message locations, jumped to system header files, looked up manual pages in it, ran a unix shell in it, and ran the program in the unix shell and interacted with it

this took about four minutes and 8.8 billion instructions. (just starting up emacs and shutting it down that way takes 595 million, but i wanted to get an estimate of the steady state.) this is about 30–40 million instructions per second, not counting the instructions of the compiler, shell, terminal emulator, and x-windows server; so 100 million per second with a more elaborate configuration and larger files seems like a plausible estimate

— ae power usage —

i wrote the same program again in anthony howe's 'ant's editor' from 01991⁰, which is about 300 lines of c in its non-obfuscated form, and is roughly the simplest programming editor you can actually use; the user interface is a stripped-down version of vi where you exit insert mode with control-l, write the file with capital w, and exit with capital q. this took about 7 minutes (i kept hitting the wrong keys) and 39 million instructions, of which about 0.8 million were startup and shutdown. that's about 90 thousand instructions per second, or 100 microwatts: a thousand times faster than emacs, and within the capabilities of a commodore 64 or apple ][. of course that again doesn't account for the window system, compiler, and terminal emulator, but it does account for ncurses computing the minimal updates necessary to the screen, so it's most of the work needed to avoid redrawing unchanged areas

38 million instructions divided by 278 bytes of output is about 137000 instructions per byte, but of course moving around in a larger file takes longer

— uxn left power usage —

running uxnemu left.rom in the same way from https://rabbits.srht.site/uxn/uxn-essentials-lin64.tar.gz takes 481 million instructions to start up and shut down. writing the same c in left.rom took about 5 minutes and 3.4 billion instructions; 3 billion instructions over 5 minutes is about 10 million instructions per second. this suggests that it uses about a third as much power as emacs and 110 times as much power as ae

10 million interpreted bytecode instructions per second is really pushing the limits of what the zorzpad can do. also its window is by default 684×374, about 33% bigger than the zorzpad's two screens put together, and it doesn't seem to be resizable (which i assume means it's not designed to be able to handle being resized)

— vim power usage —

finally, i did it again with vim in a terminal emulator, with syntax highlighting and manual page lookup, and vim took 680 million instructions, exactly one fifth of what left took. it took me less time, but i don't think vim does any background computation. as with ae, vim's time includes the time to compute minimal screen updates (confirmed with `asciinema rec vimtest`)

______

http://canonical.org/~kragen/sw/dev3/ae.c

¹ https://wiki.xxiivv.com/site/left.html

1 comments

aha, i finally figured out that yes, indeed, my elisp code is being compiled to native code and saved as shared library files in /usr/lib/emacs/28.2/native-lisp/28.2-e4556eb6. the functions have names like F76632d63616c6c2d6261636b656e64_vc_call_backend_0@@Base (the hex string decodes to 'vc-call-backend'), and all the calls are indirected through registers, but `objdump -d` can decode it into recognizable amd64 assembly language, with function prologues and epilogues, nop-padding to 8-byte boundaries, tests followed by conditional jumps, that kind of thing. so emacs doesn't really have an excuse for being so slow

i thought that maybe the earlier version of left in c would be more efficient, so i git cloned https://git.sr.ht/~rabbits/left, checked out 4f127602e4e9c27171ef8f6c11f2bc7698c6157c, and built the last c version of the editor. a simple startup and shutdown cost 407 million instructions, and writing the same c program in it again in more or less the same way took 2½ minutes and 1.8 billion instructions. 1.4 billion instructions in 150 seconds are about 9 million instructions per second, which is surprisingly about the same as the version running in uxn. but just leaving it open for 2¼ minutes also used only 424 million instructions, so maybe it makes more sense to compare the 1.4 billion against the 8.8 billion of emacs, the 0.039 billion of ae, the 3.4 billion of uxn left, and the 0.68 billion of vim, since it seems to grow primarily with activity rather than just time open

Hey kragen,

Someone just told me to have a look at the thread and I'm very happy I did! It's been really good for me to read back you two's exchange. I'm not here to defend uxn or anything like that, I was only wondering, could you do the same test with uxn11(instead of uxnemu)? I don't personally use uxnemu, I find it's too demanding for my laptop, I would love to have the data for uxn11 in comparison to uxnemu from your system if you can run X11 programs.

Let me know :) Cheers!

oh hi! delighted to hear from you! i hope it's clear i'm not here to attack uxn either

let's see about uxn11... initial signs are good, 175711 instructions to start up and shutdown rather than hundreds of millions. but after using it to go through the whole left editing session, it's 175645 instructions; that suggests the real work is being done in a child process

yeah, strace confirms there's a child process being spawned off. i'll have to see if i can disable that to get more accurate measurements with valgrind, later today

i'm interested to hear your thoughts about how left and other uxn apps might be made usable under the constraints of the zorzpad display hardware: two 400×240 screens, each 35×58mm, with only black and white (no greyscale). left itself seems like it might be relatively easy to run usably on one of them?

Of course, I've really enjoyed your exploration of uxn, and all your comments are accurate.

Uxn11 has a special device to spawn linux processes(like playing a mp3 on disk with aplay), it can be disabled in devices/console, I wonder why it would be acting up, left doesn't do any request to the console's special ports I think, I'll have to double-check.

Left is pretty heavy, it does A LOT, it's definitely not a simple text editor, not only does it do a lot of work locating symbols and navigation strings, the front-end uses a proportional font and does a lot of positioning for it.

I don't think left would be a good candidate for zorzpad, I can imagine a simpler IDE that uses fixed width font, and doesn't try to make any sense of the tal code, syntax highlight, and doesn't support utf-8 glyphs - But Left is not it.

I've ported the classic macintosh notepad application, which I now use daily for taking notes, it has proportional font support, but is monochrome and has a small window, doesn't do anything fancy. Expanding this into a proper text editor with scrolling might be more realistic than trying to fit left to a monochrome screen.

https://git.sr.ht/~rabbits/uxn-utils/tree/main/item/gui/note...

But really, I think it'd be better to write a whole new text editor specifically for zorzpad, left has a very specific goal in mind, and I can imagine one like it designed specifically for the zorzpad. Writing text editors, or block editors, is an art that shouldn't be forgotten, anyone who's got an opportunity to write one, should do it.

I've read as much of your works as I could find, you've been a big influence on the work I do nowadays, it's an honor to read a message from you. Thank you.

aw, thanks, i'm really flattered—i admire your work a lot, and i'm glad to hear i've contributed somewhat to it. you're very welcome

as for proportional fonts, a few years back i wrote a microbenchmark for proportional font layout with word wrap to see how cheap i could get it. it's http://canonical.org/~kragen/sw/dev3/propfont.c (maybe make sure you redirect stdout to a file if you run it), and it uses the n×6 font i designed for http://canonical.org/~kragen/bible-columns, derived from janne kujala's 4×6 font. the notes in the comments say that on my old laptop it ran at 70 megabytes per second, which is probably about 60 instructions per byte. if you redrew 32 lines of text with 32 characters each (about what you could fit on the zorzpad's two screens) it would be about 60000 instructions, about a microsecond at the apollo3's theoretical 60 dmips; that might be a reasonable thing to do after each keystroke. and there are some notes in there about how you could optimize it more

running the same benchmark on my current laptop i get numbers from 64 to 68 megabytes per second, but for comparability with the editors, i should say that cachegrind measures 1,482,006,535 instructions for running 100000 iterations of rendering 126 bytes, which works out to about 118 instructions per byte and 120 000 instructions for the screen-redrawing example

(of course that computation takes about 2 microseconds, while actually updating the screen will take 50000 microseconds according to the datasheet, 16700 microseconds according to some other people's experimental results, so the computation may not be the tall pole in the tent here)

propfont.c might get a lot faster if its pixels were bits instead of bytes, especially on something like the thumb-2 apollo3, which has bitfield update instructions. then again, it would get slower with a larger pixel font size

I'm currently away from reliable network and I can't manage to load the bible-columns image, I will try once we return to Canada.

I've added proportional fonts to Left because, after writing loads of THINK Pascal, I felt like I needed it, and I still enjoy this a lot more than fixed-width, but it annoys a lot of people, even even I like to write space-padded files from time to time so Left has to support both.

If I was golfing an editor(one that I would actually have to use each day), I think I would make a block editor, fixed-width, and by its block-paginated design would do away with gap buffers altogether by needed to move very little data around.

An early version of Left tried something different where it would only display one @symbol at a time. In Uxn, "scope" or objects are defined with @label, and methods by &method, making it so it's well usable if you have a list of objects, and methods a-la Smalltalk's System Navigator. During editing, you never insert into the text file, but in a gap buffer made of only the object or method being edited. I always found that design pretty neat, the main downsize is when you want to add non-source files, then you have to contend with editing to a single large buffer.

The font encoding for Left is https://wiki.xxiivv.com/site/ufx_format.html, which allows me to calculate the sprite address glyph width sort-of quickly, the issue is that varvara has no blitter, everything is drawn as tiles so it creates a bit of overdraw for each glyph. If you have a blitter, then I think there would be pretty smart encodings for drawing proportional fonts that would make them more efficient.