Macro.classify_atom - binary fast path - #15768
Open
dkuku wants to merge 3 commits into
Open
Conversation
Atoms made exclusively of ASCII letters, numbers and underscores, beginning with a lowercase letter or underscore and optionally ending with ? or !, are always identifiers, and only atoms prefixed by "Elixir" are candidates for aliases. Recognizing both directly on the binary avoids building a charlist and running the unicode aware identifier tokenizer, which dominates the cost of classifying keyword list, map and struct keys when inspecting them. Both are matched at once because the first byte tells them apart and matching them separately would set up and throw away a second match context. For the same reason the alias scan branches between two states instead of returning the rest of the binary from a helper, which would build a sub binary per piece. The special form and quoted operator atoms move into guards so that no binary is built for atoms that are not callable. Inspecting a keyword list of 8 pairs goes from 10.4us to 8.9us (1.17x), a list of 8 module atoms from 4.0us to 3.5us (1.15x). Atoms that still fall through to the tokenizer pay ~5-10% for the extra scan. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The classification of ASCII identifiers and aliases is boundary heavy: only one trailing ? or !, only at the end, and the "Elixir" prefix is an alias only when every following piece starts with an uppercase letter. None of it was covered, so add the cases that separate identifiers and aliases from atoms that merely look like them. These pass before and after the binary classification fast path, pinning it to the tokenizer's verdict. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
josevalim
reviewed
Aug 19, 2026
| cond do | ||
| atom in [:%, :%{}, :{}, :<<>>, :..., :.., :., :..//, :->] -> | ||
| :not_callable | ||
| defp inner_classify(atom) |
Member
There was a problem hiding this comment.
Can you please keep it as a cond, as that change is unrelated to this pull request? Change only the code that affects the benchmark.
josevalim
reviewed
Aug 19, 2026
| end | ||
| end | ||
|
|
||
| describe "classify_atom/1" do |
Member
There was a problem hiding this comment.
Those test cases seem excessive and I believe we already test this functionality by proxy through other places.
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.
:identifier - the atom can be used as a variable or local function call (as well as be an unquoted atom)Assisted-by: Claude Opus 5