Skip to content

Commit

Permalink
Optimize further reducing the inlining of function applications
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Viir committed Jul 18, 2023
1 parent 873cb33 commit 29a9d0b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
2 changes: 1 addition & 1 deletion implement/elm-time/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions implement/elm-time/elm-time.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>ElmTime</RootNamespace>
<AssemblyName>elm-time</AssemblyName>
<AssemblyVersion>2023.0717.0.0</AssemblyVersion>
<FileVersion>2023.0717.0.0</FileVersion>
<AssemblyVersion>2023.0718.0.0</AssemblyVersion>
<FileVersion>2023.0718.0.0</FileVersion>
<Nullable>enable</Nullable>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>
Expand Down

0 comments on commit 29a9d0b

Please sign in to comment.