Skip to content

Commit f033cfe

Browse files
committed
More optimizations attempts
1 parent 26037fe commit f033cfe

File tree

4 files changed

+276
-147
lines changed

4 files changed

+276
-147
lines changed

build.fsx

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

141+
// runFableWithArgs ("watch " + libDir) [
142+
// "--outDir " + buildDir
143+
// "--fableLib " + buildDir
144+
// "--exclude Fable.Core"
145+
// "--define FX_NO_BIGINT"
146+
// "--define FABLE_LIBRARY"
147+
// ]
148+
141149
let buildLibraryTs() =
142150
let projectDir = "src/fable-library"
143151
let buildDirTs = "build/fable-library-ts"
@@ -175,6 +183,7 @@ let testJsFast() =
175183
]
176184

177185
runFableWithArgs "src/fable-compiler-js/src" [
186+
"--forcePkgs"
178187
"--exclude Fable.Core"
179188
"--define LOCAL_TEST"
180189
]

src/Fable.Transforms/Fable2Babel.fs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -926,36 +926,24 @@ module Util =
926926
// | Fable.NewList (headAndTail, _) when List.contains "FABLE_LIBRARY" com.Options.Define ->
927927
// makeList com ctx r headAndTail
928928
// Optimization for bundle size: compile list literals as List.ofArray
929-
| Replacements.ListLiteral(exprs, t) ->
930-
[|List.rev exprs |> makeArray com ctx|]
931-
|> libCall com ctx r "List" "newList"
932-
// match exprs with
933-
// | [] -> libCall com ctx r "List" "empty" [||]
934-
// | [TransformExpr com ctx expr] -> libCall com ctx r "List" "singleton" [|expr|]
935-
// | exprs -> [|makeArray com ctx exprs|] |> libCall com ctx r "List" "ofArray"
936929
| Fable.NewList (headAndTail, _) ->
937-
match headAndTail with
938-
| None -> libCall com ctx r "List" "empty" [||]
939-
| Some(TransformExpr com ctx head, TransformExpr com ctx tail) ->
930+
let rec getItems acc = function
931+
| None -> List.rev acc, None
932+
| Some(head, Fable.Value(Fable.NewList(tail, _),_)) -> getItems (head::acc) tail
933+
| Some(head, tail) -> List.rev (head::acc), Some tail
934+
match getItems [] headAndTail with
935+
| [], None ->
936+
libCall com ctx r "List" "empty" [||]
937+
| [TransformExpr com ctx expr], None ->
938+
libCall com ctx r "List" "singleton" [|expr|]
939+
| exprs, None ->
940+
[|List.rev exprs |> makeArray com ctx|]
941+
|> libCall com ctx r "List" "newList"
942+
| [TransformExpr com ctx head], Some(TransformExpr com ctx tail) ->
940943
libCall com ctx r "List" "cons" [|head; tail|]
941-
942-
// let rec getItems acc = function
943-
// | None -> List.rev acc, None
944-
// | Some(head, Fable.Value(Fable.NewList(tail, _),_)) -> getItems (head::acc) tail
945-
// | Some(head, tail) -> List.rev (head::acc), Some tail
946-
// match getItems [] headAndTail with
947-
// | [], None ->
948-
// libCall com ctx r "List" "empty" [||]
949-
// | [TransformExpr com ctx expr], None ->
950-
// libCall com ctx r "List" "singleton" [|expr|]
951-
// | exprs, None ->
952-
// [|makeArray com ctx exprs|]
953-
// |> libCall com ctx r "List" "ofArray"
954-
// | [TransformExpr com ctx head], Some(TransformExpr com ctx tail) ->
955-
// libCall com ctx r "List" "cons" [|head; tail|]
956-
// | exprs, Some(TransformExpr com ctx tail) ->
957-
// [|makeArray com ctx exprs; tail|]
958-
// |> libCall com ctx r "List" "ofArrayWithTail"
944+
| exprs, Some(TransformExpr com ctx tail) ->
945+
[|List.rev exprs |> makeArray com ctx; tail|]
946+
|> libCall com ctx r "List" "newListWithTail"
959947
| Fable.NewOption (value, t) ->
960948
match value with
961949
| Some (TransformExpr com ctx e) ->
@@ -1210,11 +1198,11 @@ module Util =
12101198

12111199
| Fable.ListHead ->
12121200
// get range (com.TransformAsExpr(ctx, fableExpr)) "head"
1213-
libCall com ctx range "List" "head" [|com.TransformAsExpr(ctx, fableExpr)|]
1201+
libCall com ctx range "List" "head_" [|com.TransformAsExpr(ctx, fableExpr)|]
12141202

12151203
| Fable.ListTail ->
12161204
// get range (com.TransformAsExpr(ctx, fableExpr)) "tail"
1217-
libCall com ctx range "List" "tail" [|com.TransformAsExpr(ctx, fableExpr)|]
1205+
libCall com ctx range "List" "tail_" [|com.TransformAsExpr(ctx, fableExpr)|]
12181206

12191207
| Fable.TupleIndex index ->
12201208
match fableExpr with

0 commit comments

Comments
 (0)