binaryage / binaryage/cljs-devtools

Is dead code elimination really working?

未关闭
#37 11 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
cljs-bug help wanted
主要语言
Clojure
星标
1.1k
派生
51
PR 合并指标
30 天内没有已合并 PR

描述

I can't seem to bring the code size down with a barely empty project through dead-code elimination alone, even when following the installation instructions to the letter.

The template used was [reagent-figwheel](https://github.com/gadfly361/reagent-figwheel) with only `devtools` and `reagent` as dependencies. I've fiddled with the `goog.DEBUG` flag, and then removed `devtools` from the `:require` and `:dependencies` vectors.

| Type | Size |
|--------------------------------------------------------|-------:|
| `:dependencies` + `:require` + `goog.DEBUG true` | 1.9 MB |
| `:dependencies` + `:require` + `goog.DEBUG false` | 1.5 MB |
| `:dependencies` + `:require` + no mention at all | 1.6 MB |
| `:dependencies` + no `:require` + no mention at all | 763 KB |
| no `:dependencies` + no `:require` + no mention at all | 763 KB |

The first two rows followed the instructions from the [release notes](https://github.com/binaryage/cljs-devtools/releases/tag/v0.5.3). There's a single mention of ` (devtools/install!)` within a `(when ^boolean js/goog.DEBUG ...)` block. The other three had this line removed manually.

Google Closure's shaved 400kb of the build, but that's still a 800kb increase for a `:require` without a single mention of `devtools`! Is this the best I can expect from dead code elimination?

Here's the code used for the builds (e.g. `lein new reagent-figwheel +devtools`):
```clojure
;##################
;### profile.cljs

(defproject devtools-dce "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.229"]
[reagent "0.6.0"]
[binaryage/devtools "0.8.2"]]

[...]

:cljsbuild
{:builds
[{:id "min"
:source-paths ["src/cljs"]
:compiler {:main devtools-dce.core
:optimizations :advanced
:output-to "resources/public/js/compiled/app.js"
:output-dir "resources/public/js/compiled/min"
:closure-defines {goog.DEBUG false}
:pseudo-names true ;; added to exacerbate size difference
:pretty-print false}}

]})

;##############
;## core.cljs

(ns devtools-dce.core
(:require
[reagent.core :as reagent]
[devtools.core :as devtools]
))

[...]

(defn dev-setup [] ;; inlining into `main` made no difference
(when ^boolean js/goog.DEBUG
(enable-console-print!)
(println "dev mode")
(devtools/install!)
))

(defn ^:export main []
(dev-setup)
(reload))
```

贡献指南

这个仓库没有索引到贡献指南

调研方向

从 profile.cljs 中的构建配置以及 core.cljs 中的 namespace 和 dev-setup 入口点开始,使用 reagent-figwheel 模板和列出的 advanced-optimization 设置。重现五个 build 并比较它们的输出大小;完成标准是说明未使用的 devtools 依赖是否会被消除,并记录或纠正观察到的结果。

由索引模型根据 Issue 内容生成。

评估

技术栈
clojure
领域
build-system
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。