Skip to content

Commit

Permalink
More optimizations attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
ncave committed Nov 28, 2020
1 parent 2deed1d commit 3316418
Show file tree
Hide file tree
Showing 4 changed files with 277 additions and 147 deletions.
10 changes: 10 additions & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,21 @@ let buildLibrary() =

let watchLibrary() =
let libDir = "src/fable-library"
let buildDir = fullPath "build/fable-library"
printfn "Watching %s..." libDir
chokidar
.watch(libDir)
.on("change", fun _ -> buildLibrary())
|> ignore

// runFableWithArgs ("watch " + libDir) [
// "--outDir " + buildDir
// "--fableLib " + buildDir
// "--exclude Fable.Core"
// "--define FX_NO_BIGINT"
// "--define FABLE_LIBRARY"
// ]

let buildLibraryTs() =
let projectDir = "src/fable-library"
let buildDirTs = "build/fable-library-ts"
Expand Down Expand Up @@ -163,6 +172,7 @@ let testJsFast() =
]

runFableWithArgs "src/fable-compiler-js/src" [
"--forcePkgs"
"--exclude Fable.Core"
"--define LOCAL_TEST"
]
Expand Down
48 changes: 18 additions & 30 deletions src/Fable.Transforms/Fable2Babel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -926,36 +926,24 @@ module Util =
// | Fable.NewList (headAndTail, _) when List.contains "FABLE_LIBRARY" com.Options.Define ->
// makeList com ctx r headAndTail
// Optimization for bundle size: compile list literals as List.ofArray
| Replacements.ListLiteral(exprs, t) ->
[|List.rev exprs |> makeArray com ctx|]
|> libCall com ctx r "List" "newList"
// match exprs with
// | [] -> libCall com ctx r "List" "empty" [||]
// | [TransformExpr com ctx expr] -> libCall com ctx r "List" "singleton" [|expr|]
// | exprs -> [|makeArray com ctx exprs|] |> libCall com ctx r "List" "ofArray"
| Fable.NewList (headAndTail, _) ->
match headAndTail with
| None -> libCall com ctx r "List" "empty" [||]
| Some(TransformExpr com ctx head, TransformExpr com ctx tail) ->
let rec getItems acc = function
| None -> List.rev acc, None
| Some(head, Fable.Value(Fable.NewList(tail, _),_)) -> getItems (head::acc) tail
| Some(head, tail) -> List.rev (head::acc), Some tail
match getItems [] headAndTail with
| [], None ->
libCall com ctx r "List" "empty" [||]
| [TransformExpr com ctx expr], None ->
libCall com ctx r "List" "singleton" [|expr|]
| exprs, None ->
[|List.rev exprs |> makeArray com ctx|]
|> libCall com ctx r "List" "newList"
| [TransformExpr com ctx head], Some(TransformExpr com ctx tail) ->
libCall com ctx r "List" "cons" [|head; tail|]

// let rec getItems acc = function
// | None -> List.rev acc, None
// | Some(head, Fable.Value(Fable.NewList(tail, _),_)) -> getItems (head::acc) tail
// | Some(head, tail) -> List.rev (head::acc), Some tail
// match getItems [] headAndTail with
// | [], None ->
// libCall com ctx r "List" "empty" [||]
// | [TransformExpr com ctx expr], None ->
// libCall com ctx r "List" "singleton" [|expr|]
// | exprs, None ->
// [|makeArray com ctx exprs|]
// |> libCall com ctx r "List" "ofArray"
// | [TransformExpr com ctx head], Some(TransformExpr com ctx tail) ->
// libCall com ctx r "List" "cons" [|head; tail|]
// | exprs, Some(TransformExpr com ctx tail) ->
// [|makeArray com ctx exprs; tail|]
// |> libCall com ctx r "List" "ofArrayWithTail"
| exprs, Some(TransformExpr com ctx tail) ->
[|List.rev exprs |> makeArray com ctx; tail|]
|> libCall com ctx r "List" "newListWithTail"
| Fable.NewOption (value, t) ->
match value with
| Some (TransformExpr com ctx e) ->
Expand Down Expand Up @@ -1210,11 +1198,11 @@ module Util =

| Fable.ListHead ->
// get range (com.TransformAsExpr(ctx, fableExpr)) "head"
libCall com ctx range "List" "head" [|com.TransformAsExpr(ctx, fableExpr)|]
libCall com ctx range "List" "head_" [|com.TransformAsExpr(ctx, fableExpr)|]

| Fable.ListTail ->
// get range (com.TransformAsExpr(ctx, fableExpr)) "tail"
libCall com ctx range "List" "tail" [|com.TransformAsExpr(ctx, fableExpr)|]
libCall com ctx range "List" "tail_" [|com.TransformAsExpr(ctx, fableExpr)|]

| Fable.TupleIndex index ->
match fableExpr with
Expand Down
Loading

0 comments on commit 3316418

Please sign in to comment.