Smallest functioning snap challenge


#1

I recently discovered Sparky and Bash Shell RPG, which are two very small snaps in the store. Sparky is ~32KB and Bash Shell RPG is 8KB on disk. Compare this to the largest snaps (I have installed) Xonotic (915MB) and Android Studio (718.6MB) and we’re on a different scale of size and functionality, of course.

Somewhere in between is Mosaic, the classic web browser, which uses 2.9MB of disk space. This got me wondering what the smallest snap people could make, which was actually useful, functional and/or fun. Obviously “hello-world” can be made very small indeed, but where’s the fun in (yet) another hello-world app? :slight_smile:

So how about a challenge, a contest if you will? Over the summer (sorry southern hemisphere!) we have a go at making some small, functional snapped applications? What can you pack into a few KB? I don’t think we should set a hard upper limit, because someone might pack amazing things in 1MB. Perhaps lets aim for 1.44MB though as a soft target?

Perhaps for this fun contest, rather than hunt down all the smallest, coolest 4k demos from the demo-scene, it would be nice if people came up with new things to snap.

Command line applications which don’t need opengl or pulseaudio will need fewer bundled libraries. Although graphical applications which don’t use desktop toolkits can also be relatively small.

I suspect there’s a small (4K or so) overhead in the squashfs header, and the need for a snap.yaml in the snap, so I don’t think you can get below that (prove me wrong?).

Oh, and snapping a 1K script which then downloads 1GB at run-time is cheating :smiley:

It could be a utility, game or full blown graphical application. There’s no limit, and no theme. Just build something, put it in the store, and link it under this thread when done! :smiley:

If you need help or inspiration, just ask!


#2

OK, to kick this off, I’ve just snapped my Obfuscated Christmas 2017
demo “3dxmas-demo” - after some tweaks to the linker and compiler, I got
this down to an 8K snap, even on x86-64, which was tricky because it
contains a lot of floating point code.

The C source if you are interested is:

This is a simple ncurses text demo of 3D rotating and scaling images.

Colin


#3

Just as a reference point, an empty squashfs is 4k.

Two small snaps that I think are useful:


and a couple of graphical ones:



#4

[popey] popey https://forum.snapcraft.io/u/popey
July 17

Perhaps for this fun contest, rather than hunt down all the smallest,
coolest 4k demos from the demo-scene, it would be nice if people came up
with new things to snap.

I managed to squeeze a C program down to a 4K snap last night using some
hacks with gcc and strip:

There is more scope by removing some more of the ELF header and one can
use sstrip [1] to shink object code further, but I didn’t go that far.
Anyhow, I crammed an 8 bit pink noise generator in C down to a 4K snap;
I don’t think it’s possible to get any smaller.

[1] https://github.com/BR903/ELFkickers/tree/master/sstrip

I suspect there’s a small (4K or so) overhead in the squashfs header,
and the need for a snap.yaml in the snap, so I don’t think you can get
below that (prove me wrong?).

I’d be interested if it’s possible to get the snap smaller using
nefarious means :wink:

Colin


#5

Yes, it is very possible to get the unpacked snap size much smaller than the 4K limit. Attached is a fully functional brainfuck compiler. The binary is 166 bytes and the snap.yaml is 42 bytes. There’s nothing else in the snap at all.

Usage: b < source file > outputbinary

The binary itself is a very hacked elf file to minimise space. I’ve stolen it from http://www.muppetlabs.com/~breadbox/software/tiny/useless.html and the code is under the GPL.

Enjoy!

https://ovh.themcphails.uk/index.php/s/YHH8j5ADzbfERGT


#6

Of course, if we can’t compress the snap below the 4K limit, we can still add loads of apps to the snap:


#7

It is possible to make a squashfs (hence snap) smaller than 4K with the -nopad option to mksquashfs but it then fails snap-review.

alan@KinkPad-K450:~/snap_pack_demo$ mksquashfs mysnap zz_0_all.snap -noappend -comp xz -all-root -no-xattrs -no-fragments -nopad
Parallel mksquashfs: Using 4 processors
Creating 4.0 filesystem on zz_0_all.snap, block size 131072.
[================================================================================================================================================================================|] 1/1 100%

Exportable Squashfs 4.0 filesystem, xz compressed, data block size 131072
        compressed data, compressed metadata, no fragments, no xattrs
        duplicates are removed
Filesystem size 0.31 Kbytes (0.00 Mbytes)
        101.26% of uncompressed filesystem size (0.31 Kbytes)
Inode table size 102 bytes (0.10 Kbytes)
        100.00% of uncompressed inode table size (102 bytes)
Directory table size 55 bytes (0.05 Kbytes)
        100.00% of uncompressed directory table size (55 bytes)
Number of duplicate files found 0
Number of inodes 3
Number of files 1
Number of symbolic links  0
Number of device nodes 0
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 2
Number of ids (unique uids + gids) 1
Number of uids 1
        root (0)
Number of gids 1
        root (0)
alan@KinkPad-K450:~/snap_pack_demo$ ls -l
total 8
drwxrwxr-x 3 alan alan 4096 Jul 19 10:52 mysnap
-rw-r--r-- 1 alan alan  321 Jul 19 11:20 zz_0_all.snap
alan@KinkPad-K450:~/snap_pack_demo$ snap-review zz_0_all.snap 
Errors
------
 - security-snap-v2:squashfs_repack_checksum
        checksums do not match. Please ensure the snap is created with either 'snapcraft pack <DIR>' (using snapcraft >= 2.38) or 'mksquashfs <dir> <snap> -noappend -comp xz -all-root -no-xattrs -no-fragments'. If using electron-builder, please upgrade to latest stable (>= 20.14.7). See https://forum.snapcraft.io/t/automated-reviews-and-snapcraft-2-38/4982/17 for details.
        https://forum.snapcraft.io/t/automated-reviews-and-snapcraft-2-38/4982/17
zz_0_all.snap: FAIL