perf: replace list length-checks with pattern matching#128
Merged
mhanberg merged 1 commit intoelixir-tools:mainfrom Apr 23, 2026
Merged
Conversation
katafrakt
commented
Apr 15, 2026
| arity = length(args) | ||
| case args do | ||
| [_, _ | _] -> | ||
| arity = length(args) |
Contributor
Author
There was a problem hiding this comment.
We still need arity here to pass to Macro.operator? and Macro.special_form?, but we calculate it only if we know it's more than one.
mkaput
approved these changes
Apr 15, 2026
mhanberg
pushed a commit
that referenced
this pull request
Apr 15, 2026
Less obvious (for me) than #128, but also seems like a quick perf win. Perhaps surprisingly, using tail recursion is generally faster than Keyword.has_key? by about 10%. In this case though the most important thing is that we iterate over the list only once, instead of 2-3 times. The benchmark shows 7-8% improvement on parsing files.
This replaces few length check on hot paths with patternmatching. According to benchmarks I ran it gives 3-8% or performance gains on parsing a realistic files.
4594904 to
e927453
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This replaces few length check on hot paths with patternmatching. According to benchmarks I ran it gives 3-8% or performance gains on parsing a realistic files.