Skip to content

Commit

Permalink
More optimizations attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
ncave committed Jan 1, 2021
1 parent 01bb843 commit 69802d1
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 147 deletions.
9 changes: 9 additions & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ let buildLibraryIfNotExists() =
if not (pathExists (baseDir </> "build/fable-library")) then
buildLibrary()

// 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 @@ -172,6 +180,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 @@ -928,36 +928,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 @@ -1212,11 +1200,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 69802d1

Please sign in to comment.