Skip to content

Commit 28cfaad

Browse files
committed
More optimizations attempts
1 parent a167187 commit 28cfaad

File tree

3 files changed

+245
-147
lines changed

3 files changed

+245
-147
lines changed

build.fsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ let buildLibraryIfNotExists() =
150150
if not (pathExists (baseDir </> "build/fable-library")) then
151151
buildLibrary()
152152

153+
// runFableWithArgs ("watch " + libDir) [
154+
// "--outDir " + buildDir
155+
// "--fableLib " + buildDir
156+
// "--exclude Fable.Core"
157+
// "--define FX_NO_BIGINT"
158+
// "--define FABLE_LIBRARY"
159+
// ]
160+
153161
let buildLibraryTs() =
154162
let projectDir = "src/fable-library"
155163
let buildDirTs = "build/fable-library-ts"
@@ -178,6 +186,7 @@ let testJsFast() =
178186
]
179187

180188
runFableWithArgs "src/fable-compiler-js/src" [
189+
"--forcePkgs"
181190
"--exclude Fable.Core"
182191
"--define LOCAL_TEST"
183192
]

src/Fable.Transforms/Fable2Babel.fs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -933,36 +933,24 @@ module Util =
933933
// | Fable.NewList (headAndTail, _) when List.contains "FABLE_LIBRARY" com.Options.Define ->
934934
// makeList com ctx r headAndTail
935935
// Optimization for bundle size: compile list literals as List.ofArray
936-
| Replacements.ListLiteral(exprs, t) ->
937-
[|List.rev exprs |> makeArray com ctx|]
938-
|> libCall com ctx r "List" "newList"
939-
// match exprs with
940-
// | [] -> libCall com ctx r "List" "empty" [||]
941-
// | [TransformExpr com ctx expr] -> libCall com ctx r "List" "singleton" [|expr|]
942-
// | exprs -> [|makeArray com ctx exprs|] |> libCall com ctx r "List" "ofArray"
943936
| Fable.NewList (headAndTail, _) ->
944-
match headAndTail with
945-
| None -> libCall com ctx r "List" "empty" [||]
946-
| Some(TransformExpr com ctx head, TransformExpr com ctx tail) ->
937+
let rec getItems acc = function
938+
| None -> List.rev acc, None
939+
| Some(head, Fable.Value(Fable.NewList(tail, _),_)) -> getItems (head::acc) tail
940+
| Some(head, tail) -> List.rev (head::acc), Some tail
941+
match getItems [] headAndTail with
942+
| [], None ->
943+
libCall com ctx r "List" "empty" [||]
944+
| [TransformExpr com ctx expr], None ->
945+
libCall com ctx r "List" "singleton" [|expr|]
946+
| exprs, None ->
947+
[|List.rev exprs |> makeArray com ctx|]
948+
|> libCall com ctx r "List" "newList"
949+
| [TransformExpr com ctx head], Some(TransformExpr com ctx tail) ->
947950
libCall com ctx r "List" "cons" [|head; tail|]
948-
949-
// let rec getItems acc = function
950-
// | None -> List.rev acc, None
951-
// | Some(head, Fable.Value(Fable.NewList(tail, _),_)) -> getItems (head::acc) tail
952-
// | Some(head, tail) -> List.rev (head::acc), Some tail
953-
// match getItems [] headAndTail with
954-
// | [], None ->
955-
// libCall com ctx r "List" "empty" [||]
956-
// | [TransformExpr com ctx expr], None ->
957-
// libCall com ctx r "List" "singleton" [|expr|]
958-
// | exprs, None ->
959-
// [|makeArray com ctx exprs|]
960-
// |> libCall com ctx r "List" "ofArray"
961-
// | [TransformExpr com ctx head], Some(TransformExpr com ctx tail) ->
962-
// libCall com ctx r "List" "cons" [|head; tail|]
963-
// | exprs, Some(TransformExpr com ctx tail) ->
964-
// [|makeArray com ctx exprs; tail|]
965-
// |> libCall com ctx r "List" "ofArrayWithTail"
951+
| exprs, Some(TransformExpr com ctx tail) ->
952+
[|List.rev exprs |> makeArray com ctx; tail|]
953+
|> libCall com ctx r "List" "newListWithTail"
966954
| Fable.NewOption (value, t) ->
967955
match value with
968956
| Some (TransformExpr com ctx e) ->
@@ -1217,11 +1205,11 @@ module Util =
12171205

12181206
| Fable.ListHead ->
12191207
// get range (com.TransformAsExpr(ctx, fableExpr)) "head"
1220-
libCall com ctx range "List" "head" [|com.TransformAsExpr(ctx, fableExpr)|]
1208+
libCall com ctx range "List" "head_" [|com.TransformAsExpr(ctx, fableExpr)|]
12211209

12221210
| Fable.ListTail ->
12231211
// get range (com.TransformAsExpr(ctx, fableExpr)) "tail"
1224-
libCall com ctx range "List" "tail" [|com.TransformAsExpr(ctx, fableExpr)|]
1212+
libCall com ctx range "List" "tail_" [|com.TransformAsExpr(ctx, fableExpr)|]
12251213

12261214
| Fable.TupleIndex index ->
12271215
match fableExpr with

0 commit comments

Comments
 (0)