From 29a9d0bdb72d7742a0fed7bfa30da6101bf04168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20R=C3=A4tzel?= Date: Tue, 18 Jul 2023 21:22:57 +0000 Subject: [PATCH] Optimize further reducing the inlining of function applications Optimize for smaller emitted module sizes and less processing in the Elm compiler: Remove the inlining of function declarations in `emitExpressionInDeclarationBlock` Later stages will implement more inlining to optimize code emitted here for runtime. Moving the inlining to later stages makes it easier for many source languages like Elm/Roc/Gren/Cara/etc. to benefit from these optimizations. Testing this change with a part of the Elm core Dict module from (https://github.com/elm/core/blob/84f38891468e8e153fc85a9b63bdafd81b24664e/src/Dict.elm) showed a reduction of the emitted module size to half the previous size. The inlining can also lead to a smaller aggregate size, so this change will also make some modules larger. We could keep inlining here and make it more adaptive, but at the moment, I prefer the simpler Elm compiler implementation. --- .../src/ElmInteractive.elm | 60 +++++++------------ implement/elm-time/Program.cs | 2 +- implement/elm-time/elm-time.csproj | 4 +- 3 files changed, 25 insertions(+), 41 deletions(-) diff --git a/implement/elm-time/ElmTime/compile-elm-program/src/ElmInteractive.elm b/implement/elm-time/ElmTime/compile-elm-program/src/ElmInteractive.elm index b1e31097..9b958e94 100644 --- a/implement/elm-time/ElmTime/compile-elm-program/src/ElmInteractive.elm +++ b/implement/elm-time/ElmTime/compile-elm-program/src/ElmInteractive.elm @@ -2323,44 +2323,28 @@ emitExpressionInDeclarationBlock : -> List ( String, Expression ) -> Expression -> Result String Pine.Expression -emitExpressionInDeclarationBlock stack originalEnvironmentDeclarations = - let - environmentDeclarations = - originalEnvironmentDeclarations - |> List.map - (Tuple.mapSecond - (inlineApplicationsOfEnvironmentDeclarations stack originalEnvironmentDeclarations) - ) - in - \originalMainExpression -> - let - mainExpression = - inlineApplicationsOfEnvironmentDeclarations - stack - environmentDeclarations - originalMainExpression - in - emitExpressionInDeclarationBlockLessClosureArgument - stack - environmentDeclarations - mainExpression - |> Result.andThen - (\emitInClosureResult -> - case emitInClosureResult.closureCaptures of - Nothing -> - Ok emitInClosureResult.expr - - Just closureCaptures -> - { closureCaptures = closureCaptures } - |> emitClosureArgument stack - |> Result.mapError ((++) "Failed to emit closure argument for declaration block: ") - |> Result.map - (\closureArgumentPine -> - partialApplicationExpressionFromListOfArguments - [ closureArgumentPine ] - emitInClosureResult.expr - ) - ) +emitExpressionInDeclarationBlock stack environmentDeclarations mainExpression = + emitExpressionInDeclarationBlockLessClosureArgument + stack + environmentDeclarations + mainExpression + |> Result.andThen + (\emitInClosureResult -> + case emitInClosureResult.closureCaptures of + Nothing -> + Ok emitInClosureResult.expr + + Just closureCaptures -> + { closureCaptures = closureCaptures } + |> emitClosureArgument stack + |> Result.mapError ((++) "Failed to emit closure argument for declaration block: ") + |> Result.map + (\closureArgumentPine -> + partialApplicationExpressionFromListOfArguments + [ closureArgumentPine ] + emitInClosureResult.expr + ) + ) emitExpressionInDeclarationBlockLessClosureArgument : diff --git a/implement/elm-time/Program.cs b/implement/elm-time/Program.cs index cc472dec..0fe77b8e 100644 --- a/implement/elm-time/Program.cs +++ b/implement/elm-time/Program.cs @@ -17,7 +17,7 @@ namespace ElmTime; public class Program { - public static string AppVersionId => "2023-07-17"; + public static string AppVersionId => "2023-07-18"; private static int AdminInterfaceDefaultPort => 4000; diff --git a/implement/elm-time/elm-time.csproj b/implement/elm-time/elm-time.csproj index be042b6f..bf929197 100644 --- a/implement/elm-time/elm-time.csproj +++ b/implement/elm-time/elm-time.csproj @@ -5,8 +5,8 @@ net7.0 ElmTime elm-time - 2023.0717.0.0 - 2023.0717.0.0 + 2023.0718.0.0 + 2023.0718.0.0 enable true