Skip to content

Commit c4bb6b8

Browse files
committed
More optimizations attempts
1 parent 092995f commit c4bb6b8

File tree

4 files changed

+277
-148
lines changed

4 files changed

+277
-148
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
@@ -930,36 +930,24 @@ module Util =
930930
// | Fable.NewList (headAndTail, _) when List.contains "FABLE_LIBRARY" com.Options.Define ->
931931
// makeList com ctx r headAndTail
932932
// Optimization for bundle size: compile list literals as List.ofArray
933-
| Replacements.ListLiteral(exprs, t) ->
934-
[|List.rev exprs |> makeArray com ctx|]
935-
|> libCall com ctx r "List" "newList"
936-
// match exprs with
937-
// | [] -> libCall com ctx r "List" "empty" [||]
938-
// | [TransformExpr com ctx expr] -> libCall com ctx r "List" "singleton" [|expr|]
939-
// | exprs -> [|makeArray com ctx exprs|] |> libCall com ctx r "List" "ofArray"
940933
| Fable.NewList (headAndTail, _) ->
941-
match headAndTail with
942-
| None -> libCall com ctx r "List" "empty" [||]
943-
| Some(TransformExpr com ctx head, TransformExpr com ctx tail) ->
934+
let rec getItems acc = function
935+
| None -> List.rev acc, None
936+
| Some(head, Fable.Value(Fable.NewList(tail, _),_)) -> getItems (head::acc) tail
937+
| Some(head, tail) -> List.rev (head::acc), Some tail
938+
match getItems [] headAndTail with
939+
| [], None ->
940+
libCall com ctx r "List" "empty" [||]
941+
| [TransformExpr com ctx expr], None ->
942+
libCall com ctx r "List" "singleton" [|expr|]
943+
| exprs, None ->
944+
[|List.rev exprs |> makeArray com ctx|]
945+
|> libCall com ctx r "List" "newList"
946+
| [TransformExpr com ctx head], Some(TransformExpr com ctx tail) ->
944947
libCall com ctx r "List" "cons" [|head; tail|]
945-
946-
// let rec getItems acc = function
947-
// | None -> List.rev acc, None
948-
// | Some(head, Fable.Value(Fable.NewList(tail, _),_)) -> getItems (head::acc) tail
949-
// | Some(head, tail) -> List.rev (head::acc), Some tail
950-
// match getItems [] headAndTail with
951-
// | [], None ->
952-
// libCall com ctx r "List" "empty" [||]
953-
// | [TransformExpr com ctx expr], None ->
954-
// libCall com ctx r "List" "singleton" [|expr|]
955-
// | exprs, None ->
956-
// [|makeArray com ctx exprs|]
957-
// |> libCall com ctx r "List" "ofArray"
958-
// | [TransformExpr com ctx head], Some(TransformExpr com ctx tail) ->
959-
// libCall com ctx r "List" "cons" [|head; tail|]
960-
// | exprs, Some(TransformExpr com ctx tail) ->
961-
// [|makeArray com ctx exprs; tail|]
962-
// |> libCall com ctx r "List" "ofArrayWithTail"
948+
| exprs, Some(TransformExpr com ctx tail) ->
949+
[|List.rev exprs |> makeArray com ctx; tail|]
950+
|> libCall com ctx r "List" "newListWithTail"
963951
| Fable.NewOption (value, t) ->
964952
match value with
965953
| Some (TransformExpr com ctx e) ->
@@ -1213,11 +1201,11 @@ module Util =
12131201

12141202
| Fable.ListHead ->
12151203
// get range (com.TransformAsExpr(ctx, fableExpr)) "head"
1216-
libCall com ctx range "List" "head" [|com.TransformAsExpr(ctx, fableExpr)|]
1204+
libCall com ctx range "List" "head_" [|com.TransformAsExpr(ctx, fableExpr)|]
12171205

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

12221210
| Fable.TupleIndex index ->
12231211
match fableExpr with

0 commit comments

Comments
 (0)