【问题标题】:ocaml 4.01.0 → 4.02.1, binary size became largerocaml 4.01.0 → 4.02.1,二进制大小变大
【发布时间】:2014-10-30 11:59:21
【问题描述】:

在 Ubuntu 14.04,32 位:

➥ cat test.ml
let () = print_endline "hello";

➥ opam switch list | grep " C "
4.01.0  C 4.01.0  Official 4.01.0 release

➥ ocamlopt test.ml 
➥ ls -l a.out
-rwxrwxr-x 1 shorrty shorrty 158569 Oct.  30 13:29 a.out

➥ opam switch 4.02.0
➥ eval `opam config env`

➥ ocamlopt test.ml 
➥ ls -l a.out
-rwxrwxr-x 1 shorrty shorrty 171122 Oct.  30 13:30 a.out

➥ opam switch 4.02.1
➥ eval `opam config env`

➥ ocamlopt test.ml 
➥ ls -l a.out
-rwxrwxr-x 1 shorrty shorrty 171196 Oct.  30 14:08 a.out

可执行文件大小越来越大:158569 → 171122 → 171196。

在更复杂的应用程序中,文件的大小增加得更多。

任何想法如何解决?

更新 #1

试过strip:

➥ strip -V | head -n 1
GNU strip (GNU Binutils for Ubuntu) 2.24

➥ ls -l
-rwxrwxr-x 1 shorrty shorrty 158569 Oct.  30 15:22 a.4.01.0.out
-rwxrwxr-x 1 shorrty shorrty 117368 Oct.  30 15:26 a.4.01.0.out.stripped
-rwxrwxr-x 1 shorrty shorrty 171122 Oct.  30 15:03 a.4.02.0.out
-rwxrwxr-x 1 shorrty shorrty 127580 Oct.  30 15:26 a.4.02.0.out.stripped
-rwxrwxr-x 1 shorrty shorrty 171196 Oct.  30 15:21 a.4.02.1.out
-rwxrwxr-x 1 shorrty shorrty 127612 Oct.  30 15:26 a.4.02.1.out.stripped
-rwxrwxr-x 1 shorrty shorrty 158569 Oct.  30 15:21 a.out

继续增长:117368 → 127580 → 127612

更新 #2

尝试了选项-compact,没有用:

➥ opam switch 4.01.0 && eval `opam config env`

➥ ocamlopt test.ml && ls -l a.out
-rwxrwxr-x 1 shorrty shorrty 158569 Oct.  30 22:02 a.out

➥ ocamlopt -compact test.ml && ls -l a.out
-rwxrwxr-x 1 shorrty shorrty 158569 Oct.  30 22:03 a.out

➥ opam switch 4.02.1 && eval `opam config env`

➥ ocamlopt test.ml && ls -l a.out
-rwxrwxr-x 1 shorrty shorrty 171196 Oct.  30 22:05 a.out

➥ ocamlopt -compact test.ml && ls -l a.out
-rwxrwxr-x 1 shorrty shorrty 171196 Oct.  30 22:05 a.out

尝试了选项-inline,也没有用:

➥ opam switch 4.01.0 && eval `opam config env`

➥ ocamlopt -inline 0 test.ml && ls -l a.out
-rwxrwxr-x 1 shorrty shorrty 158569 Oct.  30 22:07 a.out

➥ ocamlopt -inline 1 test.ml && ls -l a.out
-rwxrwxr-x 1 shorrty shorrty 158569 Oct.  30 22:07 a.out

➥ opam switch 4.02.1 && eval `opam config env`

➥ ocamlopt -inline 0 test.ml && ls -l a.out
-rwxrwxr-x 1 shorrty shorrty 171196 Oct.  30 22:08 a.out

➥ ocamlopt -inline 1 test.ml && ls -l a.out
-rwxrwxr-x 1 shorrty shorrty 171196 Oct.  30 22:09 a.out

【问题讨论】:

  • 有意思,你试过脱衣吗?
  • 在帖子中添加了关于strip的信息。
  • 后一个版本增加了更激进的内联,这可以解释它。
  • 还有一个-compact选项(用于原生编译);这将优化空间而不是速度。
  • 最后,-no-alias-deps 可能会在 4.02.0 中有所帮助——确保您没有在依赖模块中使用副作用。

标签: size ocaml native-code


【解决方案1】:

您的代码没有更改,但它调用了在 4.01 和 4.02 之间更改的 pervasives 模块。

值得注意的是,关于格式的部分已更改为使用基于 GADT 的格式而不是字符串。 这尤其使 to_string、of_string 和串联(相当)重。

更多详情请见this discussion

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-21
    • 1970-01-01
    • 2017-03-22
    • 1970-01-01
    • 2018-01-30
    • 1970-01-01
    • 2021-12-30
    相关资源
    最近更新 更多