Optimize comparison of parsed versions - #15748
Merged
Merged
Conversation
josevalim
approved these changes
Aug 14, 2026
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.
Version.compare/2converted parsed%Version{}values into two five-element tuples before comparing them. This adds a struct-to-struct clause that passes the precedence fields directly to the comparator, avoiding both tuple allocations. String and mixed operands retain parsing and validation throughto_matchable/2, then call the same field comparator. Build metadata remains ignored.Benchmarks used Elixir 1.21.0-dev, Erlang/OTP 29, macOS arm64, and one scheduler (
+S 1:1). The benchmark baseline wasbc7844c. Five runs produced 500 batch-average samples for individual comparisons and 150 complete-operation samples across six shuffled, one ascending, and one descending input order.Parsed sorting and maximum selection exclude parsing. Parsing strings once and then sorting improved by 1.09x at 895 versions and 1.06x at 2,964 versions, although the per-run median ranges overlapped. Sorting strings through the public comparator remained within run variation.
OTP
tprofallocation profiling measured 12 heap words, or 96 bytes on this VM, per baseline parsed comparison and zero words after the change. The semantic oracle compared 38,416 ordered pairs, including arbitrary-size core and prerelease integers, mixed and prefix prerelease lists, stable releases, build ties, and long identifiers, with no mismatches.make formatandmake test_stdlib TEST_FILES=version_test.exspass with 43 tests.