Hi Andy and all, Looking at the disassembly of -O1 code in a quest for more concise bytecode¹ (a quest that’s not necessarily always relevant but probably is at -O1), I noticed a few things:
1. Code for free variable lookup, emitted by ‘emit-cached-toplevel-box’, is too large (~7 instructions per variable) for little in return. 2. The ‘.data’ section is surprisingly large: for each symbol in the source, we end up in that section with a string, a stringbuf (pointing to contents in the ‘.rodata’ section), and a symbol. More on that below. 3. ‘*lcm-page-size*’ is set to 64 KiB for the purposes of reducing the number of .go variants needed under prebuilt/. Should we default to sysconf(_SC_PAGESIZE) and use that common denominator only when building .go files under prebuilt/ (this requires adding a compiler flag to choose a different alignment)? (In the meantime, I changed the linker to create sparse files in commit 112b617f5921c67b4b2c45aae39f54cccd34d7ef.) Regarding ‘.data’, look: --8<---------------cut here---------------start------------->8--- $ echo sym > /tmp/t.scm $ ./meta/uninstalled-env guild compile /tmp/t.scm -o /tmp/t.go wrote `/tmp/t.go' $ readelf -a /tmp/t.go |grep -A10 "^Section Headers" readelf: Warning: [ 5]: Link field (0) should index a string section. readelf: Warning: local symbol 0 found at index >= .symtab's sh_info value of 0 readelf: Warning: local symbol 1 found at index >= .symtab's sh_info value of 0 Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .guile.procprops PROGBITS 0000000000000000 00010588 0000000000000000 0000000000000000 0 0 8 [ 2] .rodata PROGBITS 0000000000000158 00000158 0000000000000014 0000000000000000 A 0 0 8 [ 3] .data PROGBITS 0000000000010000 00010000 0000000000000058 0000000000000000 WA 0 0 8 --8<---------------cut here---------------end--------------->8--- That’s 88 bytes for ‘.data’. If ‘lookup-bound’ would take a string (instead of a symbol) like ‘lookup-bound-private’ and ‘lookup-bound-public’ do, we’d save relocations and space. Perhaps these instructions (or rather variants thereof) could even take a raw UTF-8 buffer instead? As for #1, I’m not sure what the best option is. I initially thought about adding a new macro-instruction, but then we’d lose on cache-hit path, which is not good. Thoughts? Ludo’. ¹ https://issues.guix.gnu.org/70398