Slide 1

Slide 1 text

Laketowncr kubo39

Slide 2

Slide 2 text

Crystal binary size 619KB to 704bytes ● Repo: https://github.com/kubo39/tinycr

Slide 3

Slide 3 text

619KB → 528KB ● --release build 632962bytes →540050bytes

Slide 4

Slide 4 text

528KB → 454KB ● Use strip command 540050bytes → 463944bytes

Slide 5

Slide 5 text

454KB → 10592bytes ● --prelude=empty prelude.crではなくemtpy.crをロードする 必要なライブラリは適宜自前でrequire ● https://github.com/kubo39/tinycr/commit/c0d 2e519902fa7a9cee57a004acda656f3e10e8f - libpcre依存とか消せる - この時点でインラインアセンブラ書いたりしてるが あまり意味ない

Slide 6

Slide 6 text

10592bytes → 6272bytes ● to_unsafe Stringクラスのunsafeを自前で定義しなおす ● https://github.com/kubo39/tinycr/commit/63d 5c8be5eabdf268509053aef8525064afb3eeb ● この時点でlibc以外の依存がなくなった

Slide 7

Slide 7 text

6272bytes →5480bytes ● eglibc捨ててmusl libcに静的リンク ● https://github.com/kubo39/tinycr/commit/973 284df2cd59e25245858cc79c38e3097770f6b ● とうとう依存がなくなった!! ldd helloでも確認

Slide 8

Slide 8 text

5480bytes → 5400bytes ● --gc-sections - リンク時に不要なセクション削除 ● https://github.com/kubo39/tinycr/commit/d4c 568bda484c1b7c1a9a35f02b08a4cad7fc15c

Slide 9

Slide 9 text

5400bytes → 5360bytes ● エントリポイントをmainにする 普通にやるとsegvるのでexit(2)で終了 ● https://github.com/kubo39/tinycr/commit/afcc 7aca613ce59b171b6850f1f4e130fba6e44c

Slide 10

Slide 10 text

5360bytes →704bytes ● というかもうlibc依存する処理一切ないよね、という わけで--nostdlib渡す ● https://github.com/kubo39/tinycr/commit/e2b 77fe1855aa36579459bb8f5096eae93eed4ca ● これでもちゃんと実行できます