compilation - 编译因子程序的更快方法

标签 compilation factor-lang

我真的很喜欢 Factor语。但是我发现编译用它编写的程序非常慢,因此用 Factor 创建真正的项目是不可行的。

例如编译样本Calculator WebApp在我的笔记本电脑(i3 处理器,2GB RAM,运行 Fedora 15)上大约需要 5 分钟。

我四处搜索,但找不到比使用解释器(主要因子二进制可执行文件)更快的编译因子程序的方法。

当您尝试只为每次运行使用解释器而不将您的程序“部署”到 native 二进制文件(它甚至不适用于许多程序)时,这变得很荒谬。
这意味着每次我想运行计算器时,例如,我必须等待 5 分钟的冷启动持续时间。

我想知道这是否是一个常见问题,以及是否有解决它的好方法。

最佳答案

我承认,在今天之前,我从未听说过 Factor。我借此机会玩它。它看起来不错(同时让我想起了 squeak-vm 和 lisp)。我将停止闲聊(非常有意的双关语)并跳到您的问题。
分析
看起来 Factor 的工作方式导致加载词汇表很慢。
我在我的 64 位四核 linux 系统上编译了 Factor(来自 git 修订版 60b1115452 ,10 月 6 日星期四)。把一切都放在tmpfs构建目录占用 641Mb,其中 2x114Mb 位于 factor.image 及其备份 (factor.image.fresh) 中。
strace - 在加载计算器应用程序时,加载了大量因子文件:

  • 3175 因子文件被触及。
  • 编译这些大约需要 30 秒 在我的盒子上
  • 内存使用量在 下达到最大值500Mb (虚拟)和 300Mb 保留集

  • I'm strongly suspecting your box is low on memory, and might be getting very swappy
    This would definitely explain compilation taking 5 minutes


    您能否确认是否是这种情况(可能是您正在运行某种共享主机或 VPS 设备)。如果您运行虚拟机,请考虑增加可用系统内存。

    保存堆图像(快照)
    我之前已经提到了 factor.image 文件 (114Mb)。它包含 Factor VM 的“预编译”(实际上是引导)堆镜像。 VM 中的所有操作(处理 UI 监听器或编译因子文件)都会影响堆镜像。
    为了避免一次又一次地重新编译源文件,您可以将最终结果保存到自定义堆镜像中:
    http://docs.factorcode.org/content/article-images.html

    Images

    To start Factor with a custom image, use the -i=image command line switch; see Command line switches for the VM.

    One reason to save a custom image is if you find yourself loading the same libraries in every Factor session; some libraries take a little while to compile, so saving an image with those libraries loaded can save you a lot of time.

    For example, to save an image with the web framework loaded,

    USE: furnace
    save
    

    可以从头开始创建新图像:Bootstrapping new images
    部署应用程序
    保存堆镜像会导致文件(通常)比原始引导镜像大。
    Application deployment tool创建仅包含足以运行单个应用程序的代码的精简图像

    The stand-alone application deployment tool, implemented in the tools.deploy vocabulary, compiles a vocabulary down to a native executable which runs the vocabulary's MAIN: hook. Deployed executables do not depend on Factor being installed, and do not expose any source code, and thus are suitable for delivering commercial end-user applications.

    Most of the time, the words in the tools.deploy vocabulary should not be used directly; instead, use Application deployment UI tool.

    You must explicitly specify major subsystems which are required, as well as the level of reflection support needed. This is done by modifying the deployment configuration prior to deployment.


    总结
    我希望您会受益于(按最快获胜顺序):
  • 增加可用 RAM(仅在虚拟环境中快速...)
  • 使用
  • 保存堆图像

    USE: db.sqlite
    USE: furnace.alloy
    USE: namespaces
    USE: http.server
    save
    
    This step brought the compilation on my system **down from ~`30s` to `0.835s`**
    
  • 将计算器 Web 应用程序部署到剥离的堆镜像(有关部署提示,请参阅 source)

  • 简而言之,感谢让我注意到 Factor,我希望我的发现会有所帮助,干杯

    关于compilation - 编译因子程序的更快方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7673378/

    相关文章:

    java - jar 文件将不会运行。在cmd中获取错误

    compilation - f# - 使用通用对象而不将其传递到任何地方

    c - 从 ARM 5 迁移到 ARM 6 编译器 : Use of undeclared identifier '__Vectors'

    factor-lang - 延伸词语和引文范围

    stack - 如何在 Forth(或 Factor)中编写应用程序?

    iOS 着色器在预热阶段之外编译

    c++ - Git 破坏了我的程序?

    factor-lang - 输入循环引用与预期效果不符

    functional-programming - 摆弄无点代码?