Optimize arity wrapper for << and >> #1145
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to this, << (and similarly >>) would be compiled to
which doesn't match the call sites, which is always of the shape
This change makes it so that composeL/composeR are now wrapped with A2, which improves the performance by about 30%.
Here is the benchmark that I have been using: https://github.com/jfmengels/elm-benchmarks/blob/master/src/WhatIsFaster/FunctionComposition.elm (where I compare
>>
and lambdas)Prior to the change:
![Screenshot from 2024-07-01 17-11-47](https://private-user-images.githubusercontent.com/3869412/348687759-f7a047e9-ceb9-4bb6-bec6-b1d1a8292fb7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNTMzNzYsIm5iZiI6MTczOTI1MzA3NiwicGF0aCI6Ii8zODY5NDEyLzM0ODY4Nzc1OS1mN2EwNDdlOS1jZWI5LTRiYjYtYmVjNi1iMWQxYTgyOTJmYjcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTFUMDU1MTE2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YjdiOGE0ZGQ0MDIyN2Y2YTY2Y2QzMTdhNDRjYjcyZThmMDc1ZTMxOTIxNWVjMWNmNzY4MDE2MDFkMTNjMjc4MiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.DbQykE2kK9SQtDssfspZbykce226Eb5kBQ9NeImTZxI)
After the change:
![Screenshot from 2024-07-01 17-12-32](https://private-user-images.githubusercontent.com/3869412/348687905-26d56770-ce33-4f69-8b8b-4d45666b0e2c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNTMzNzYsIm5iZiI6MTczOTI1MzA3NiwicGF0aCI6Ii8zODY5NDEyLzM0ODY4NzkwNS0yNmQ1Njc3MC1jZTMzLTRmNjktOGI4Yi00ZDQ1NjY2YjBlMmMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTFUMDU1MTE2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OGY2YWE1NDk4NTQ4MTE5NDQwNWQ5MGE0YjQwZjQyNjFjNTllZmM0MThhNTYyNTlkMTQwMzU3YWFmNDNhNjYxZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.nmRRilFN64ctONQOO5tBw-I8CywFEsd6freVj54uSQM)
A further improvement to this (not in this PR, and more in the scope of the compiler would be to replacing
![Screenshot from 2024-07-01 17-13-14](https://private-user-images.githubusercontent.com/3869412/348688001-dc37ca4b-d5e4-4494-81a3-ba2381f9fa9b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNTMzNzYsIm5iZiI6MTczOTI1MzA3NiwicGF0aCI6Ii8zODY5NDEyLzM0ODY4ODAwMS1kYzM3Y2E0Yi1kNWU0LTQ0OTQtODFhMy1iYTIzODFmOWZhOWIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTFUMDU1MTE2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MzQ2MTZjMjI5ODgzY2ZiMmUyYjgxOTdiMjIzNzU3MmE3NzgyNDc3YWQ2YmFlYzNlNWJiN2JjMjlkYTBkMTk2ZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.7pKHdsHgCG1toLNQt0ueRSyfRfSCsUwE2FKPHEyb6UU)
A2(composeL, f, g)
bycomposeL(f, g)
:PS: At some point in the past, the Elm compiler turned composition into lambdas, but it removed that in elm/compiler@6ae0168.